我的 bash 脚本中出现命令未找到错误
I am getting a command not found error in my bash script
我正在编写的这个脚本会查看目录并分别计算常规文件和目录的数量。我的代码是这样的:
#!/bin/bash
#countf.sh
#this file counts the number of files and directories in a path recursively
#Variables
declare -i filecount="0"
declare -i dircount="0"
for file in /*
do
if [ -f $file ]
then
$((filecount++))
elif [ -d $file ]
then
$((dircount++))
fi
done
echo The number of files is "$filecount"
echo The number of directories is "$dircount"
echo $?
我得到的输出是:
./countf.sh: line 14: 0: command not found
./countf.sh: line 14: 1: command not found
./countf.sh: line 14: 2: command not found
./countf.sh: line 14: 3: command not found
./countf.sh: line 14: 4: command not found
./countf.sh: line 14: 5: command not found
./countf.sh: line 11: 0: command not found
./countf.sh: line 11: 1: command not found
./countf.sh: line 14: 6: command not found
./countf.sh: line 14: 7: command not found
./countf.sh: line 14: 8: command not found
./countf.sh: line 14: 9: command not found
./countf.sh: line 14: 10: command not found
./countf.sh: line 14: 11: command not found
./countf.sh: line 14: 12: command not found
./countf.sh: line 14: 13: command not found
./countf.sh: line 14: 14: command not found
./countf.sh: line 14: 15: command not found
./countf.sh: line 14: 16: command not found
./countf.sh: line 14: 17: command not found
./countf.sh: line 14: 18: command not found
./countf.sh: line 14: 19: command not found
./countf.sh: line 14: 20: command not found
./countf.sh: line 14: 21: command not found
./countf.sh: line 11: 2: command not found
./countf.sh: line 11: 3: command not found
The number of files is 4
The number of directories is 22
0
除了文件计数或目录计数递增后出现的命令未找到错误代码外,脚本似乎工作正常。
在第 14 行,替换
$((dircount++))
来自
((dircount++))
我正在编写的这个脚本会查看目录并分别计算常规文件和目录的数量。我的代码是这样的:
#!/bin/bash
#countf.sh
#this file counts the number of files and directories in a path recursively
#Variables
declare -i filecount="0"
declare -i dircount="0"
for file in /*
do
if [ -f $file ]
then
$((filecount++))
elif [ -d $file ]
then
$((dircount++))
fi
done
echo The number of files is "$filecount"
echo The number of directories is "$dircount"
echo $?
我得到的输出是:
./countf.sh: line 14: 0: command not found
./countf.sh: line 14: 1: command not found
./countf.sh: line 14: 2: command not found
./countf.sh: line 14: 3: command not found
./countf.sh: line 14: 4: command not found
./countf.sh: line 14: 5: command not found
./countf.sh: line 11: 0: command not found
./countf.sh: line 11: 1: command not found
./countf.sh: line 14: 6: command not found
./countf.sh: line 14: 7: command not found
./countf.sh: line 14: 8: command not found
./countf.sh: line 14: 9: command not found
./countf.sh: line 14: 10: command not found
./countf.sh: line 14: 11: command not found
./countf.sh: line 14: 12: command not found
./countf.sh: line 14: 13: command not found
./countf.sh: line 14: 14: command not found
./countf.sh: line 14: 15: command not found
./countf.sh: line 14: 16: command not found
./countf.sh: line 14: 17: command not found
./countf.sh: line 14: 18: command not found
./countf.sh: line 14: 19: command not found
./countf.sh: line 14: 20: command not found
./countf.sh: line 14: 21: command not found
./countf.sh: line 11: 2: command not found
./countf.sh: line 11: 3: command not found
The number of files is 4
The number of directories is 22
0
除了文件计数或目录计数递增后出现的命令未找到错误代码外,脚本似乎工作正常。
在第 14 行,替换
$((dircount++))
来自
((dircount++))