[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*
相关推荐
lwx9148525 小时前
Linux-特殊权限SUID,SGID,SBIT
linux·运维·服务器
皮卡狮6 小时前
Linux权限的概念
linux
炘爚6 小时前
深入解析printf缓冲区与fork进程复制机制
linux·运维·算法
workflower6 小时前
注塑机行业目前自动化现状分析
运维·人工智能·语言模型·自动化·集成测试·软件工程·软件需求
小义_7 小时前
随笔 3(Linux)
linux·运维·服务器·云原生·红帽
#六脉神剑7 小时前
MySQL参数调优:十个关键参数助力数据库性能数倍提升
运维·mysql
cccccc语言我来了7 小时前
Linux(10)进程概念
linux·运维·服务器
伐尘8 小时前
【linux】查看空间(内存、磁盘、文件目录、分区)的几个命令
linux·运维·网络
Deitymoon8 小时前
linux——PV操作
linux
倔强的胖蚂蚁8 小时前
x2openEuler 辅助机完整部署教程
运维·云原生