概述
正如其他人所指出的那样,有一个在bash没有goto(或其他POSIX样弹) - 其它更为灵活的流量控制结构取而代之。
在man bash中查找标题Compound Commands。
对您而言,select命令是正确的选择。 由于如何使用它可能不是很明显,这里的东西让你开始:
#!/usr/bin/env bash
echo "Main Menu"
# Define the choices to present to the user, which will be
# presented line by line, prefixed by a sequential number
# (E.g., '1) copy', ...)
choices=('copy' 'exit')
# Present the choices.
# The user chooses by entering the *number* before the desired choice.
select choice in "${choices[@]}"; do
# If an invalid number was chosen, $choice will be empty.
# Report an error and prompt again.
[[ -n $choice ]] || { echo "Invalid choice." >&2; continue; }
# Examine the choice.
# Note that it is the choice string itself, not its number
# that is reported in $choice.
case $choice in
copy)
echo "Copying..."
# Set flag here, or call function, ...
;;
exit)
echo "Exiting. "
exit 0
esac
# Getting here means that a valid choice was made,
# so break out of the select statement and continue below,
# if desired.
# Note that without an explicit break (or exit) statement,
# bash will continue to prompt.
break
done
最后
以上就是成就朋友为你收集整理的linux 网站监控脚本 有goto 吗,如何在shell脚本中使用goto语句的全部内容,希望文章能够帮你解决linux 网站监控脚本 有goto 吗,如何在shell脚本中使用goto语句所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复