[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*
相关推荐
thinkMoreAndDoMore2 小时前
linux内核匹配I2C设备
linux·运维·服务器
PatrickYao04227 小时前
Hydro OJ部署完全指南!
服务器·oj·hydro·在线评测
小政同学8 小时前
【NFS故障】共享的文件无法执行
linux·运维·服务器
不会写DN8 小时前
受保护的海报图片读取方案 - 在不公开静态资源目录下如何获取静态资源
服务器
AI木马人8 小时前
3.【Prompt工程实战】如何设计一个可复用的Prompt系统?(避免每次手写提示词)
linux·服务器·人工智能·深度学习·prompt
ch3nyuyu8 小时前
Ubuntu(乌班图)基础指令
linux·运维·网络
minglie19 小时前
gcc编译器汇总
linux
挽安学长9 小时前
保姆级教程,通过GACCode使用Claude Code Desktop!
运维·服务器
firstacui9 小时前
MGRE实验
运维·服务器·网络
白菜欣10 小时前
Linux —《开发三件套:gcc/g++、gdb、make/Makefile 全解析》
linux·运维