How do I prompt for Yes/No/Cancel input in a Linux shell script?

后端 未结 30 1665
不思量自难忘°
不思量自难忘° 2020-11-22 04:52

I want to pause input in a shell script, and prompt the user for choices.
The standard Yes, No, or Cancel type question.
How d

30条回答
  •  孤街浪徒
    2020-11-22 05:02

    To get a nice ncurses-like inputbox use the command dialog like this:

    #!/bin/bash
    if (dialog --title "Message" --yesno "Want to do something risky?" 6 25)
    # message box will have the size 25x6 characters
    then 
        echo "Let's do something risky"
        # do something risky
    else 
        echo "Let's stay boring"
    fi
    

    The dialog package is installed by default at least with SUSE Linux. Looks like:

提交回复
热议问题