Skip to content

Instantly share code, notes, and snippets.

@ixti
Last active January 26, 2023 14:57
Show Gist options
  • Save ixti/4664169bd4820e98990e7ea3ef9838e9 to your computer and use it in GitHub Desktop.
Save ixti/4664169bd4820e98990e7ea3ef9838e9 to your computer and use it in GitHub Desktop.
Shell helper function to show yes/no prompt
function aye_or_nay() {
local response
local result
while [[ -z "${result:-}" ]]; do
echo -n "$1 (y/n) "
read response
case "$(echo "${response}" | tr '[:upper:]' '[:lower:]')" in
aye | yes | y )
result=true
;;
nay | no | n )
result=false
;;
* )
echo "Could you please repeat"
esac
done
$result
}
if aye_or_nay "Do you like it?"; then
echo "I'm glad you liked it!"
else
echo "Well, your loss!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment