-1
我正試圖實現Unix的which
函數,但不斷收到語法錯誤,我認爲是合法的?這是我的實現:實現shell中的哪個函數
IFS=":"
x=false
for i in $*
do
for j in $PATH
do
if [ -x "${j}/$i" ];then
echo $j/$i
x=true
break
fi
done
if [ $x == false ]; then
echo my_which $i not found in --$PATH--
fi
x=false
done
我不斷收到以下錯誤
$ bash which.sh
: command not found:
'which.sh: line 5: syntax error near unexpected token `do
'which.sh: line 5: `do
...另外,'=='不是POSIX字符串比較運算符 - 它是'=';有些實現可能會接受'==',但標準並不要求它們這樣做。請參閱http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html –
...並始終引用您的擴展。 'echo「my_which $我找不到 - $ PATH - 」' –
複製粘貼您發佈的代碼並再次測試。 –