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
You can use the built-in read command ; Use the -p
option to prompt the user with a question.
Since BASH4, you can now use -i
to suggest an answer :
read -e -p "Enter the path to the file: " -i "/usr/local/etc/" FILEPATH
echo $FILEPATH
(But remember to use the "readline" option -e
to allow line editing with arrow keys)
If you want a "yes / no" logic, you can do something like this:
read -e -p "
List the content of your home dir ? [Y/n] " YN
[[ $YN == "y" || $YN == "Y" || $YN == "" ]] && ls -la ~/