Skip to content

Instantly share code, notes, and snippets.

@marshki
Last active February 27, 2024 23:43
Show Gist options
  • Save marshki/be14159a311efa60ab583906f23a7ecc to your computer and use it in GitHub Desktop.
Save marshki/be14159a311efa60ab583906f23a7ecc to your computer and use it in GitHub Desktop.
Bash loop for the forgetful.
#!/usr/bin/env bash
#
# Simple loop in Bash
while : ; do
printf "%s\n" "Do this!"
printf "%s\n" "Do that!"
printf "%s\n" "And this, too!"
read -rp "Do you wish to continue (yes/no)?: " reply
printf "%s\n" "$reply"
if [[ "$reply" == "yes" ]]; then
printf "%s\n" "OK. I'll give you some more."
elif [[ "$reply" == "no" ]]; then
printf "%s\n" "Now, you are free."
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment