[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*
相关推荐
鱼很腾apoc8 分钟前
【Linux】第7期 进程间通信 (IPC) 详解:管道 (匿名 / 命名) + System V
linux·服务器·c语言·学习·进程间通信·ipc
毒爪的小新9 分钟前
踩坑实录 | RAG知识库完整搭建-Milvus2.4+BGE大中文AI模型嵌入
linux·人工智能·ai·milvus·rag
zh731410 分钟前
docker日志监控dozzle,高性能,性能消耗小
运维·docker·容器
yxl8746464619 分钟前
PCTG-1015型Profinet转Ethernet/IP协议转换器
服务器·网络·物联网·网络协议·自动化·信息与通信
weixin_4713830322 分钟前
Docker - 05 - Railway 部署
运维·docker·容器
你觉得脆皮鸡好吃吗22 分钟前
【THM】JWT Security & Protocols and Servers(AI)
运维·服务器·网络
江畔柳前堤33 分钟前
第15章:docker故障排查与面试题
大数据·运维·git·elasticsearch·docker·容器·eureka
洪恒远34 分钟前
Windows 配置 Gerrit SSH Key
运维·ssh
2023自学中1 小时前
imx6ull 开发板, mame 模拟器,运行游戏 测试
linux·游戏·嵌入式·开发板
云飞云共享云桌面1 小时前
搭建10人SolidWorks云设计环境:云飞云在非标自动化工厂的实测方案
运维·服务器·网络·数据库·自动化·电脑