Bash脚本的循环控制与故障排查
1. 循环控制
1.1 while循环的使用
在脚本中,使用 while 循环可以让程序在每次选择后重复显示菜单。以下是一个示例代码:
DELAY=3
while true; do
clear
cat <<- _EOF_
Please Select:
1. Display System Information
2. Display Disk Space
3. Display Home Space Utilization
0. Quit
_EOF_
read -p "Enter selection [0-3] > "
if [[ "$REPLY" =~ ^[0-3]$ ]]; then
if [[ "$REPLY" == 1 ]]; then
echo "Hostname: $HOSTNAME"
uptime
sleep "$DELAY"
continue
fi
if [[ "$REPLY" == 2 ]]; then
df -h
sleep "$DELAY"
continue
fi
if [[ "$REPLY" == 3 ]]; then
if [[ "
超级会员免费看
订阅专栏 解锁全文
320

被折叠的 条评论
为什么被折叠?



