[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*
相关推荐
bukeyiwanshui4 小时前
20260622 安装配置ubuntu
linux·运维·ubuntu
tonydf4 小时前
.NET 项目集成可观测性:从架构思考到落地实践
运维·后端
qq_163135754 小时前
Linux 【03- netstat命令超详细教程】
linux
cjhbachelor4 小时前
线程的控制
linux
金智维科技官方4 小时前
AI驱动的应付账款自动化,落地时要拆解哪些流程?
运维·人工智能·自动化
写代码的学渣4 小时前
Linux 彻底清空历史命令 & 恢复历史命令(完整版、重启永久生效)
linux·运维·chrome
fei_sun5 小时前
ARP(地址解析协议)与NDP(邻居发现协议)
运维·服务器
生万千欢喜心5 小时前
liunx AnolisOS-8.9-x86_64-dvd.iso win11 适配龙蜥 - 虚拟机
linux
Qimooidea6 小时前
祁木 CAD Translator 全套功能 & 官网入口汇总
运维·服务器
天空'之城6 小时前
Linux 系统编程 12:TCP 进阶
linux·网络编程