我采购软件的shell脚本,但我不断收到以下错误语句(?):猛砸正确的,如果未正确执行
>source thefile.sh
'else' builtin not inside of if block
我检查了理论上的错误块,我不能发现什么不对的结构
if [ condition ]
then
if [ condition2 ]
then
dostuff
else
dostuffagain
fi
else # this is the else which generates the error
stuffstuffstuff
fi
我看不出什么错:这是一个嵌套的if/then和每一个如果由它自己的网络连接终止。为什么外壳会对此感到不安?
是否'thefile.sh'直接执行时没有错误执行?这可能是一个有价值的信息,因为例如当采购 – Aaron
替换'condition'和'stuff'有意义时,shebangs会被忽略,您的示例适用于我。 – Robin479
检查http://shellcheck.net上的整个文件。祝你好运。 – shellter