shell脚本数组报错Syntax error: "(" unexpected-centos易出现问
2018-01-03 22:40
871 查看
按照正常的shell数组定义,例如3.sh
在这里,sh被重定向到dash,因此,如果执行./3.sh,则使用的是dash
避免报错可有多种方法,例如执行 bash example.sh,或者,将脚本第一行改为
#!/bin/bash,执行./3.sh也可以。
cat 3.sh #!/bin/sh a=( 1 2 3) for number in ${a[@]} do echo $number done 执行命令 sh 3.sh 3.sh: 2: 3.sh: Syntax error: "(" unexpected 执行该脚本,在有的机器上会报错Syntax error: "(" unexpected bash 3.sh 1 2 3 与你实际使用的shell版本有关。你可以用 ls -l /bin/*sh 打印出来,例如: ls -l /bin/*sh -rwxr-xr-x 1 root root 1021112 Oct 7 2014 /bin/bash -rwxr-xr-x 1 root root 121272 Feb 19 2014 /bin/dash lrwxrwxrwx 1 root root 4 Dec 4 01:40 /bin/rbash -> bash lrwxrwxrwx 1 root root 4 Dec 4 01:40 /bin/sh -> dash lrwxrwxrwx 1 root root 7 Nov 14 2013 /bin/static-sh -> busybox
在这里,sh被重定向到dash,因此,如果执行./3.sh,则使用的是dash
避免报错可有多种方法,例如执行 bash example.sh,或者,将脚本第一行改为
#!/bin/bash,执行./3.sh也可以。
相关文章推荐
- shell脚本数组报错Syntax error: "(" unexpected
- shell脚本数组报错Syntax error: "(" unexpected
- shell脚本----调试脚本时候出现Syntax error: "(" unexpected错误解决
- shell脚本 数组操作报Syntax error: "(" unexpected
- ubuntu下执行shell脚本报错 Syntax error: "(" unexpected
- Ubuntu 16.04下Shell脚本中使用数组提示:Syntax error: "(" unexpected
- 在执行shell脚本时,出现“syntax error : unexpected end of file"错误的解决方法
- shell脚本调试报错:"syntax error: unexpected end of file"
- 执行脚本是报错./cross.install: 25: Syntax error: "do" unexpected (expecting "fi")
- 【Linux】Shell脚本“syntax error: unexpected end of file”原因及处理
- openwrt移植程序时出现line 1: syntax error: unexpected "("
- shell脚本“syntax error:unexpected end of file”解决方案
- 关于编译源码时出现Syntax error: "(" unexpected的解决方式
- shell脚本报错:"[: =: unary operator expected"
- shell脚本报错:"[: =: unary operator expected"
- shell脚本“syntax error:unexpected end of file”解决方案
- shell脚本报错:"[: =: unary operator expected"
- netca 配置 local naming method报错-TNS-04605: Invalid syntax error: Unexpected char or LITERAL "(" befor
- shell脚本报错:"[: =: unary operator expected"
- Shell脚本报错--syntax error near unexpected token for((i=0;i<$length;i++))