нужна помощь с моей программой меню

Этот мне кажется более элегантным:

curl --silent --output /dev/null http://example.com

Кроме того, если вы хотите увидеть код HTTP:

curl --write-out '%{http_code}' --silent --output /dev/null http://example.com

Полная документация находится здесь .

1
13.09.2020, 11:45
1 ответ

Используйте встроенный оператор selectдля меню:

#!/usr/bin/env bash
choices=(
    "print home directory,Files,user id,login shell and date"
    "generate 5 random number betweeon 0 to 100"
    "print the min and max of the generated numbers"
    "exit the program"
)
PS3='Enter your selection: '

while true; do
    clear
    echo "========================"
    echo "Menu ----"
    echo "========================"
    select answer in "${choices[@]}"; do

        # if the user entered a valid selection: 
        # - the "answer" variable will contain the _text_ of the selection,
        # - the "REPLY" variable will contain the selection _number_
        case "$REPLY" in
            1) echo "do stuff for $answer..." ;;
            2) echo "do stuff for $answer..." ;;
            3) echo "do stuff for $answer..." ;;
            4) exit ;;
        esac

        # we loop within select until a valid selection is entered.
        [[ -n "$answer" ]] && break
    done
    read -p "Hit enter to continue..."
done
1
18.03.2021, 23:05

Теги

Похожие вопросы