shell脚本数组报错Syntax error: "(" unexpected
发布时间:2020-12-15 20:08:57 所属栏目:安全 来源:网络整理
导读:按照正常的shell数组定义,例如3.sh cat 3.sh #!/bin/sha=( 1 2 3)for number in ${a[@]}doecho $numberdone执行命令sh 3.sh 3.sh: 2: 3.sh: Syntax error: "(" unexpected执行该脚本,在有的机器上会报错Syntax error: "(" unexpectedbash 3.sh 123与你实际
按照正常的shell数组定义,例如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也可以。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |