[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*
相关推荐
易保山14 分钟前
MIT6.S081 - Lab6 Copy-on-Write(写时复制)
linux·操作系统·c
獨枭34 分钟前
Linux 下安装和使用 Jupyter Notebook
linux·chrome·jupyter
Monee..44 分钟前
linux里安装pip和conda
linux·conda·pip
阳区欠1 小时前
【Linux】进程通信
linux·运维·服务器·共享内存·进程通信·system v·管道文件
may_一一2 小时前
终端SSH连接工具SecureCRT安装和连接Linux
运维·服务器·ssh
姓刘的哦2 小时前
Ubuntu环境安装
linux·运维·ubuntu
厦门德仔2 小时前
【C#】C#字符串拼接的6种方式及其性能分析对比
服务器·windows·c#
春生黎至10053 小时前
GZ073网络系统管理赛项赛题第1套模块A:网络构建解题笔记
运维·网络
IT程序媛-桃子3 小时前
【网安面经合集】42 道高频 Web 安全面试题全解析(附原理+防御+思路)
运维·网络·安全·面试
❀͜͡傀儡师3 小时前
多台服务器上docker部署 Redis 集群
运维·服务器·redis