如何修复这个bash脚本



我在这里有这个脚本:

killall -q $1
#turns out system already has a method for this, yey
#-q because we already have a error handling
returned=$?
#does this so that it doesn't read the success state of the ifs
if [ $returned = 0 ]
then 
printf "Process kill attempt returned "
echo $returned
echo "Process killed sucessfully."
#yey we did it
else
#oh noes it failed
printf "Process kill attempt returned "
echo $returned
echo "Process kill attempt failed."
printf "Most likely cause of failure: "
if [ $returned = 1 ]
then
echo "process does not exist or is not running"
elif [ $returned = 2 ]
echo "process is system task; insufficient permissions"
else
echo "unknown failure " $returned "; no known fail in database has this value"
fi
fi

当我看它的时候,我没有看到任何问题,但当运行时,我会得到这个错误。

nathan@HAL-LINUX:~$ xscreensaver
nathan@HAL-LINUX:~$ killproc xscreensaver
/usr/local/bin/killproc: line 23: syntax error near unexpected token `else'
/usr/local/bin/killproc: line 23: ` else'
nathan@HAL-LINUX:~$ 

我的原始脚本省略了嵌套的if,直接告诉你它失败了,出现了错误3、1或2。

我应该回去吗?或者有办法解决这个问题吗?

您在elif:之后忘记了then

if [ $returned = 1 ]
then
echo "process does not exist or is not running"
elif [ $returned = 2 ]
then
echo "process is system task; insufficient permissions"
else
echo "unknown failure " $returned "; no known fail in database has this value"
fi

相关内容

  • 没有找到相关文章

最新更新