Skip to content

Instantly share code, notes, and snippets.

@Alanaktion
Created January 5, 2016 23:57
Show Gist options
  • Save Alanaktion/0cc19d286a542fed49b6 to your computer and use it in GitHub Desktop.
Save Alanaktion/0cc19d286a542fed49b6 to your computer and use it in GitHub Desktop.
A basic prompt function for bash scripts
#!/bin/bash
function prompt() {
echo -n $1
echo -n " [y/n] "
read prompt_response
if [ $prompt_response == 'y' ]; then
return 0
else
return 1
fi
}
prompt "I can haz cheezburger?"
if [ $? == 0 ]; then
echo 'Yay, cheezburger!'
else
echo 'Awww... :('
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment