我正在为一个类构建一个 bourne 脚本,并且遇到了这个循环的问题。基本上,我正在构建一个循环来遍历指定目录中的所有文件,并确定有多少文件和目录以及有多少文件是可读、可写和/或可执行的。问题是,当我运行脚本时,它返回以下错误:
assignment4.sh: line 61: expr: command not found
assignment4.sh: line 61: expr: command not found
assignment4.sh: line 36: expr: command not found
assignment4.sh: line 41: expr: command not found
assignment4.sh: line 48: expr: command not found
assignment4.sh: line 55: expr: command not found
assignment4.sh: line 36: expr: command not found
assignment4.sh: line 41: expr: command not found
assignment4.sh: line 48: expr: command not found
assignment4.sh: line 36: expr: command not found
assignment4.sh: line 41: expr: command not found
assignment4.sh: line 48: expr: command not found
导致此错误的代码部分如下:
for filename in "$PATH"/"$1"/*
do
if [ -f "$filename" ]
then
files=`expr $files + 1`
if [ -r "$filename" ]
then
readable=`expr $readable + 1`
fi
if [ -w "$filename" ]
then
writeable=`expr $writeable + 1`
fi
if [ -x "$filename" ]
then
executable=`expr $executable + 1`
fi
elif [ -d "$filename" ]
then
directories=`expr $directories + 1`
fi
done
我知道 expr 在我正在运行的机器上,因为我之前使用过它并且它正在工作,尽管我确实必须像在格式化之前一样使用它来更改语句的格式
var=`expr $var+1`
并且没有以正确的方式更新变量的值。