Skip to content

Instantly share code, notes, and snippets.

@TheBox193
Created February 3, 2017 16:19
Show Gist options
  • Save TheBox193/c85d6778632dd7adb15ff46c2af76050 to your computer and use it in GitHub Desktop.
Save TheBox193/c85d6778632dd7adb15ff46c2af76050 to your computer and use it in GitHub Desktop.
Bash prompt with default value
# Description:
# A simple prompt for bash that supports a default value.
# ${ask} QUESTION DEFAULT
#
# Example:
# BRANCH=$(ask "Which Branch?" "master")
function ask(){
local QUESTION=$1
local DEFAULT=$2
local ANSWER
read -p "${QUESTION} [${DEFAULT}] " ANSWER
[ -z "${ANSWER}" ] && ANSWER=$DEFAULT
echo $ANSWER
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment