[linux] Syntax error: “(“ unexpected错误,sh报错

参考:Shell 数组 Syntax error ( unexpected_.sh 使用数组报错-CSDN博客

bash 复制代码
#!/bin/bash
arr=('a')
echo ${arr[0]}

sh test.sh执行脚本的时候,报错:Syntax error: "(" unexpected错误。

而使用下面这种方式执行,则不会报错

bash 复制代码
chmod 777 test.sh
#chmod +x test.sh
bash ./test.sh
或者./test.sh

用nohup的时候,记得如果用list的话,只能用bash

bash 复制代码
nohup bash ./shells/multi_task_env.sh >nohup.out 2>&1 &

这事实上与sh执行的shell版本有关系。通过ll /bin/*sh 可以看到 执行sh的时候实际上是执行dash。

bash 复制代码
ll /bin/*sh
-rwxr-xr-x 1 root root 1113504 May  3  2019 /bin/bash*
-rwxr-xr-x 1 root root  121432 Jan 25  2018 /bin/dash*
lrwxrwxrwx 1 root root       4 May  3  2019 /bin/rbash -> bash*
lrwxrwxrwx 1 root root       4 Jun 24  2019 /bin/sh -> dash*
lrwxrwxrwx 1 root root       7 Mar  7  2019 /bin/static-sh -> busybox*
相关推荐
mzhan0175 小时前
Linux: 重新理解调度
linux·运维·服务器
一路往蓝-Anbo5 小时前
第 4 章:串口驱动进阶——GPDMA + Idle 中断实现变长数据流接收
linux·人工智能·stm32·单片机·嵌入式硬件
SakitamaX5 小时前
haproxy七层代理介绍与实验
linux·运维·服务器
only_Klein5 小时前
Ansible变量详解
运维·自动化·ansible
武帝为此5 小时前
【Linux strace命令介绍】
linux·运维·策略模式
请为小H留灯5 小时前
Docker 命令速通指南:从入门到封神的 100 + 必学指令,一篇搞定容器全操作
运维·docker·容器
一只鹿鹿鹿6 小时前
数据治理文档(word原件)
java·运维·spring boot·后端
『往事』&白驹过隙;6 小时前
Linux VFS虚拟文件系统杂谈
linux·c语言·arm开发·物联网·操作系统·iot
亓才孓6 小时前
【MyBatis Exception】省略动态SQL中的‘‘,会造成Runtime Exception
java·服务器·mybatis