[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*
相关推荐
Linux-lucky5 小时前
21-Linux学习之旅之HTTPS和安全加固
linux·运维·学习·ubuntu·https
清水白石0086 小时前
Python 死锁排查全攻略:从线程卡死到锁依赖定位与工程化修复
linux·网络·python
ao-weilai7 小时前
Linux基础:Ext系列文件系统
linux·运维·服务器
qq_349447958 小时前
Linux系统,安装git,从使用git下载仓库(GitHub, Gitee, GitLab 等),并且使用ssh密钥,可以直接执行git pull
linux·git·ssh
GlobalSign数字证书11 小时前
小企业零运维 TLS 架构设计:证书生命周期管理(CLM)与自动化轮换策略的技术选型
运维·自动化
mCell11 小时前
GitHub Actions 玩法大赏:一台远程主机的七种活法
linux·github·agent
盐焗鹌鹑蛋11 小时前
【Linux】动静态库的制作与使用
linux
wuyk55511 小时前
Python 第三章:列表 List
服务器·开发语言·python
艾伦_耶格宇12 小时前
【ELK】-4 logstash的搭建及操作
linux·运维·ubuntu·elk