linux shell if then else,嵌套if/then/elseif如何在bash中工作?

mikyra..

43

我想你的问题是关于许多语法中包含的悬浮的其他歧义; 在bash中没有这样的事情.每个if都必须由fi标记if块结尾的伴侣分隔.

鉴于此事实(除了其他语法错误),您会注意到您的示例不是有效的bash脚本.试图修复一些错误,你可能会得到这样的东西

if condition

then

echo "do this stuff"

elif condition

then

echo "do this stuff"

elif condition

then

echo "do this stuff"

if condition

then

echo "this is nested inside"

# this else _without_ any ambiguity binds to the if directly above as there was

# no fi colosing the inner block

else

echo "this is nested inside"

# else

# echo "not nested"

# as given in your example is syntactically not correct !

# We have to close the last if block first as there's only one else allowed in any block.

fi

# now we can add your else ..

else

echo "not nested"

# ... which should be followed by another fi

fi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值