shell腳本數(shù)組報錯Syntax error: "(" unexpected(2014-06-17 18:21:35)
按照正常的shell數(shù)組定義,例如example.sh
#!/bin/sh
a=( 1 2 3)
for number in ${a[@]}
do
echo $number
done
執(zhí)行該腳本,在有的機器上會報錯Syntax error: "(" unexpected
這與你實際使用的shell版本有關(guān)。你可以用
-rwxr-xr-x 1 root root 959120 Mar 29
lrwxrwxrwx 1 root root
-rwxr-xr-x 1 root root 109768 Mar 30
lrwxrwxrwx 1 root root
lrwxrwxrwx 1 root root
lrwxrwxrwx 1 root root
lrwxrwxrwx 1 root root
在這里,sh被重定向到dash,因此,如果執(zhí)行./example.sh,則使用的是dash
避免報錯可有多種方法,例如執(zhí)行 bash example.sh,或者,將腳本第一行改為
#!/bin/bash,執(zhí)行./example.sh也可以。
有關(guān)該問題,還可以參考Ubuntu論壇:
http:///archive/index.php/t-444304.html |
|
|