[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*
相关推荐
薛定谔的悦16 小时前
光储系统 AEMS 模块的光伏控制模式设计
linux·能源·储能·bms
红叶舞17 小时前
成数据绑定对象,在应用程序中处理完数据后,将更新的数据序列化为JSON传回远端服务器,很多移动应用使用了这种模式处理服务器端的数据。 ...
运维·服务器·json
深圳恒讯17 小时前
H100服务器是什么?H100服务器适合哪些企业?
运维·服务器
翼龙云_cloud17 小时前
阿里云国际站代理商:ECS弹性伸缩 自动应对流量高峰
运维·网络·数据库·阿里云·架构
ZJH__GO17 小时前
网络编程v4--群聊和私聊的实现
运维·服务器·网络
Ivan CloudBay17 小时前
SDK 游戏盾如何隐藏游戏服务器的真实 IP?
服务器·tcp/ip·游戏
码农客栈17 小时前
U-Boot详解(三)之启动流程详解
linux·uboot
say_fall17 小时前
【Linux系统编程】文件操作基础:C标准库、系统调用、fd是什么和fd与FILE*的关系
android·linux·c语言
zcmodeltech17 小时前
智慧农业沙盘模型物联网控制系统设计:基于STM32与Modbus RTU的传感器-执行器闭环方案
服务器·分布式·stm32·嵌入式硬件·物联网·能源
邪修king17 小时前
Re:Linux系统篇(六):动静态库 & 链接机制【完整透彻版】
linux·运维·服务器