[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*
相关推荐
Dreamboat-L1 小时前
使用VMware安装centos的详细流程(保姆级教程)
linux·运维·centos
数字化顾问1 小时前
(114页PPT)华为FusionCloud私有云最佳实践RegionTypeII(附下载方式)
运维·服务器·华为
蓦然回首的风度1 小时前
【运维记录】Centos 7 基础命令缺失
linux·运维·centos
2501_938810111 小时前
共享IP的定义
服务器·网络·tcp/ip
kblj55552 小时前
学习Linux——网络基础管理
linux·网络·学习
前端世界2 小时前
用Python打造智能成绩分析系统:从异常处理到断言验证的全流程实战
服务器·数据库·python
小王C语言2 小时前
Linux基础开发工具----yum、vim和gcc/g++
linux·运维·服务器
newxtc2 小时前
【辽宁政务服务网-注册_登录安全分析报告】
运维·selenium·安全·政务·安全爆破
_w_z_j_2 小时前
Linux----文件系统
linux·运维·服务器
测试-鹏哥3 小时前
要将ITP集成到Jenkins Pipeline中,实现开发发版时自动触发自动化测试
运维·python·测试工具·ci/cd·jenkins