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

后端 未结 30 2081
不思量自难忘°
不思量自难忘° 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:11

    The easiest way to achieve this with the least number of lines is as follows:

    read -p " : y/n/cancel" CONDITION;
    
    if [ "$CONDITION" == "y" ]; then
       # do something here!
    fi
    

    The if is just an example: it is up to you how to handle this variable.

提交回复
热议问题