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

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

    read -e -p "Enter your choice: " choice
    

    The -e option enables the user to edit the input using arrow keys.

    If you want to use a suggestion as input:

    read -e -i "yes" -p "Enter your choice: " choice
    

    -i option prints a suggestive input.

提交回复
热议问题