我已經看了大約30分鐘了,現在似乎無法找到這個錯誤。它發生在我最後的if/else塊中。在意外標記'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'
您不會將shell函數作爲default()調用,您稱它們爲「default」。 – 2015-01-20 21:54:01
謝謝你解決了這個問題。現在談談我的其他問題。 – 2015-01-20 21:59:49
這裏的正確形式是一個問題的一個問題,並且在該問題中沒有比它涵蓋的單個問題更多的代碼。另請參閱http://stackoverflow.com/help/mcve – 2015-01-20 22:24:09