-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 - ”' –
复制粘贴您发布的代码并再次测试。 –