[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*
相关推荐
Qt程序员3 小时前
基于 C++ 实现自定义字符串 string 类
linux·c++·容器·指针·内存管理·运算符重载
双层吉士憨包3 小时前
Google Voice保号教程
大数据·服务器·人工智能
fengyehongWorld3 小时前
docker 常用命令
运维·docker·容器
赛博云推-Twitter热门霸屏工具3 小时前
推特自动化营销软件有哪些?2026最新推荐
运维·自动化
从零点3 小时前
认识Linux和mpu开发板之间的联系
linux
牛十二3 小时前
Ubuntu 虚拟机安装完全免费的网易有道龙虾实战流程
linux·运维·ubuntu
yangyanping201084 小时前
Linux学习三之 清空 nohup.out 文件
linux·chrome·学习
柏木乃一4 小时前
Linux线程(7)基于策略模式的日志模块
linux·运维·服务器·c++·线程·策略模式
TrueDei4 小时前
linux-C/C++主子进程同时占用主进程文件描述符问题
linux·c语言·c++
zhu62019764 小时前
【保姆级】3分钟搞定 OpenClaw 大龙虾环境:Docker 一键部署,零基础!
运维·docker·容器·openclaw