Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A bash function to write a given message and retrieve response in named variable
# First argument is the name of the variable in which you want the answer to be.
# Next arguments will compose the message to show to the user before starting
# the reading. An additional space will be added at the end of the message.
print_message_read_response() {
var_name="$1"
eval $var_name=
shift
read -p "$* " $var_name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.