ask and confirm
Here are some fun commands for user interactivity in the shell. You can use these as part of a recipe or a nice "one-liner".

ask

The ask command is similar to the ask() method in Task Runners. It requires an interactive terminal and will ask the user a question and return their answer. It is meant to be changed with other commands.
1
set color=`ask "favorite Color? "`
2
echo "you said ${color}"
Copied!
or with default values
1
ask question="Who is cool? " defaultResponse="Balbino!"
Copied!
or with masked input
1
ask question="What is your password? " mask=*
Copied!
Or fun stuff like this
1
ask "Secret phrase: " | assertEqual "mockingbird" || echo "access denied!" && exit 1
Copied!

confirm

The confirm command will ask the user a yes/no question and return a passing or failing exit code from the command based on the answer.
1
confirm "do you want to update your packages? " && update
Copied!
Remember the && operator will only execute the second command if the first command returns an exit code of 0.
Last modified 5mo ago
Copy link
Edit on GitHub
Contents
ask
confirm