2017-04-27 65 views
0

我采购软件的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和每一个如果由它自己的网络连接终止。为什么外壳会对此感到不安?

+2

是否'thefile.sh'直接执行时没有错误执行?这可能是一个有价值的信息,因为例如当采购 – Aaron

+0

替换'condition'和'stuff'有意义时,shebangs会被忽略,您的示例适用于我。 – Robin479

+0

检查http://shellcheck.net上的整个文件。祝你好运。 – shellter

回答

1

这不是bash错误消息;我发现它在source code for the fish shell

case parse_keyword_else: { 
       this->parse_error(token, parse_error_unbalancing_else, 
            L"'else' builtin not inside of if block"); 

这告诉我你想source一个bash脚本在fish壳,这是行不通的。 source通知shell(在这种情况下为fish)自己执行脚本,但fish shell的语法与脚本中使用的bash语法太不同了,因为它是合理的。

(我想你可以尝试写一个polyglot script那将会在两个bashfish工作,但是这将是困难的。)

+0

你是对的,我没有意识到我还在一个鱼壳里面!谢谢 – Mutewinter