test.sh
#!/bin/bash
arr=('a')
echo ${arr[0]}
用下面执行该脚本的时候,报了Syntax error: "(" unexpected
错误
sh test.sh
而使用下面这种方式执行,则不会报错
chmod +x test.sh
./test.sh
这事实上与sh
执行的shell版本有关系。通过ll /bin/*sh
可以看到 执行sh的时候实际上是执行dash。
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*