我正在爲一個類構建一個bourne腳本,並且遇到此循環的問題。基本上,我構建了一個循環遍歷指定目錄中的所有文件,並確定有多少文件和目錄以及多少文件可讀,可寫和/或可執行。問題是,當我運行該腳本,它返回以下錯誤:在bourne腳本中出現「expr:command not found」錯誤
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是機器我上m跑,因爲我之前用它和它的工作,雖然我也不得不改變它利用我的發言的格式之前對其進行格式化
var=`expr $var+1`
,並沒有更新的雜物ble的價值是正確的方式。
你改變了你的'$ PATH'嗎? 'type -a expr'打印什麼? – 2014-12-04 01:14:22
Bourne,還是POSIX sh?中等規模的Solaris是唯一遠程操作系統,其中'/ bin/sh'仍然是POSIX Bourne之前的版本;破折號,灰燼,busybox sh等都符合POSIX標準(標準本身大部分來自ksh),而不是Bourne。 – 2014-12-04 01:19:13
從代碼看起來您選擇PATH作爲變量名稱,並且意外地覆蓋了shell搜索路徑。 – 2014-12-04 01:25:05