linux - [Solved-6 Solutions] How to prompt user for Yes No Cancel input in a Linux shell script - ubuntu - red hat - debian - linux server - linux pc
Linux - Problem :
How to prompt user for Yes No Cancel input in a Linux shell script ?
Linux - Solution 1:
To get user input at a shell prompt is the read command.
Here is the same example using select:
With select you don't need to sanitize the input – it displays the available choices, and you type a number corresponding to your choice. It also loops automatically, so there's no need for a while true loop to retry if they give invalid input.
Linux - Solution 2:
Linux - Solution 3:
You can use the built-in read command. Use the -p option to prompt the user with a question.
Linux - Solution 4:
Bash has select for this purpose.