Bash Uppercase Input with Defaults

April 25, 2019

I needed to modify a bash function that accepted user input, so that it uppercased that input. This was implemented using a function that provided a default value.

fetchInputUpper()
{
   local entered_value
   read -p "$1 [default: $2]: " entered_value
   export $3="${entered_value:-$2}"
   export $3="${!3^^}"
}

fetchInputUpper "Enter Text?" "Default" VARIABLE
echo $VARIABLE