linux shell选择列表

1.字符选择

# echo "Please select an branch:"
# select opt in "${options[@]}"
# do
#     case $opt in
#         "S331")
#             echo "You selected Option 1"
#             ;;
#         "S600")
#             echo "You selected Option 1"
#             ;;
#         "S601")
#             echo "You selected Option 1"
#             ;;
#         "S551")
#             echo "You selected Option 1"
#             ;;
#         "Quit")
#             break
#             ;;
#         *) echo "Invalid option. Please try again.";;
#     esac
# done

2.图形选择

options=("S331" "S600" "S601" "Quit")
havewatchdog=true

selected=$(dialog --clear \
                --backtitle "Select an option" \
                --menu "Choose one option from below:" \
                15 50 5 \
                "${options[0]}" "" \
                "${options[1]}" "" \
                "${options[2]}" "" \
                2>&1 >/dev/tty)

echo "You selected $selected"

case $selected in
    "S331")
        echo "You selected Option 1"
        # 执行 Option 1 对应的操作
        ;;
    "S551")
        echo "You selected Option 2"
        # 执行 Option 2 对应的操作
        ;;
    "S600")
        echo "You selected Option 3"
        # 执行 Option 3 对应的操作
        ;;
    *)
        echo "Invalid option"
        ;;
esac

你可能感兴趣的:(linux,运维,服务器)