Last active
January 26, 2023 14:57
-
-
Save ixti/4664169bd4820e98990e7ea3ef9838e9 to your computer and use it in GitHub Desktop.
Shell helper function to show yes/no prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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