Skip to content

Instantly share code, notes, and snippets.

@TheBox193
Created February 3, 2017 16:19

Revisions

  1. TheBox193 created this gist Feb 3, 2017.
    16 changes: 16 additions & 0 deletions ask.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # 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
    }