bash – 循环(?)if语句
发布时间:2020-12-15 21:05:52 所属栏目:安全 来源:网络整理
导读:我是一个 shell脚本的菜鸟,我想知道这个: #!/usr/local/bin/bashnumber=5echo "Enter 'yes' to continue,'no' to abort:"read choiceif [ $choice = yes ]; then while [ $number -lt 10 ]; do echo "The script is now looping!" doneelif [ $choice = no
我是一个
shell脚本的菜鸟,我想知道这个:
#!/usr/local/bin/bash number=5 echo "Enter 'yes' to continue,'no' to abort:" read choice if [ $choice = yes ]; then while [ $number -lt 10 ]; do echo "The script is now looping!" done elif [ $choice = no ]; then echo "Loop aborted" else echo "Please say 'yes' or 'no'" read choice # What now? fi 如果你没有指定“是”或“否”,我将如何重新检查if选项(第13行)? 谢谢. 解决方法
>您可以将代码从“echo Enter …”直到外部“while”循环中的fi. while循环将循环,直到$choice为“yes”或“no”.这样做时删除最后一个“else”子句(这将是多余的). > P.S.你需要在内部while循环中增加(或改变)$number.否则,它将无限运行.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |