我现在已经看了大约30分钟,似乎无法找到错误。它发生在我最后的if / else块。
default()
{
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"
}
specific()
{
for file in $param
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"
}
#Variables
declare -a param=$1
declare -i filecount="0"
declare -i dircount="0"
#Action
if [ $param=='-h' ]; then
echo To use this program, enter a directory path after $0 or leave it blank to use current directory.
elif [ $param=='' ]; then
default()
else
specific()
fi
exit 0
这是错误代码。任何帮助表示赞赏。
./countf.sh: line 44: syntax error near unexpected token `else'
./countf.sh: line 44: `else'
答案 0 :(得分:0)
我只检查了你的语法并发现了这些错误。
[ $param == '-h' ]
; [ "$param" == '-h' ]
代替[ $param == '-h' ]
。请查看此内容以获取更多详Double quote to prevent globbing and word splitting 我建议你在这里测试你的脚本。 http://www.shellcheck.net/我也应该先做,而不是手动检查你的脚本。