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

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

    This solution reads a single character and calls a function on a yes response.

    read -p "Are you sure? (y/n) " -n 1
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        do_something      
    fi
    

提交回复
热议问题