shell 命令 not found

先说下我的情况,SHELL脚本如下:

#!/bin/bash
 i=1;
 for file in `ls`;do
         A[$i]=$file;
         ((i++))
 done;

使用 sh a.sh出现错误

a.sh: 4: a.sh: A[1]=1: not found
a.sh: 5: a.sh: i++: not found
a.sh: 4: a.sh: A[1]=a1.txt: not found
a.sh: 5: a.sh: i++: not found
a.sh: 4: a.sh: A[1]=a2.txt: not found
a.sh: 5: a.sh: i++: not found
a.sh: 4: a.sh: A[1]=a.sh: not found
a.sh: 5: a.sh: i++: not found
a.sh: 4: a.sh: A[1]=a.txt: not found
a.sh: 5: a.sh: i++: not found
a.sh: 4: a.sh: A[1]=b.sh: not found
a.sh: 5: a.sh: i++: not found
a.sh: 4: a.sh: A[1]=err.txt: not found
a.sh: 5: a.sh: i++: not found
a.sh: 4: a.sh: A[1]=in.txt: not found
a.sh: 5: a.sh: i++: not found
a.sh: 4: a.sh: A[1]=m.txt: not found
a.sh: 5: a.sh: i++: not found
a.sh: 4: a.sh: A[1]=rabbitmq: not found
a.sh: 5: a.sh: i++: not found

不一定是你的脚本除了问题,可能使用的bash命令是有问题的,

查看  ll /bin/sh

lrwxrwxrwx 1 root root 4 Nov  3 06:37 /bin/sh -> dash

用的是dash,解决方式,脚本头部已经有了  #!/bin/bash

接下来赋予其可执行权限即可

./a.sh 成功


猜你喜欢

转载自blog.csdn.net/dasgk/article/details/53106545