Created
February 3, 2017 16:19
-
-
Save TheBox193/c85d6778632dd7adb15ff46c2af76050 to your computer and use it in GitHub Desktop.
Bash prompt with default value
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
# 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