[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*
相关推荐
AOwhisky几秒前
Ceph系列第四期:Ceph块存储(RBD)精讲
linux·运维·笔记·ceph·云计算·rbd
Shadow(⊙o⊙)1 分钟前
库的制作与原理2.0---动静态链接,main全解析,CPU在执行文件时的作用,GOT表。
linux·运维·服务器
zincsweet3 分钟前
System V 共享内存:原理剖析、代码架构分析与双端通信实战
linux·c++
EMTime8 小时前
Docker运行OpenWRT
运维·docker·容器
lolo大魔王9 小时前
Linux 文件系统超全面详解(原理、结构、挂载、分区、inode、日志、管理命令)
linux·运维·服务器
磊 子10 小时前
详细讲解一下epoll
linux·io·epoll·io多路复用
printfLILEI11 小时前
php中的类与对象以及反序列化
linux·开发语言·php
zyl8372111 小时前
Docker 使用手册
运维·docker·容器
古月方枘Fry12 小时前
MGRE实验
运维·服务器
博客-小覃12 小时前
Zabbix之华为交换机的日志记录信息操作详细教程
服务器·网络·华为·zabbix