Skip to content

Instantly share code, notes, and snippets.

@jpcaparas
Created June 9, 2019 00:22
Show Gist options
  • Save jpcaparas/106e0d43c5f8b2761223fc248e4e4b3a to your computer and use it in GitHub Desktop.
Save jpcaparas/106e0d43c5f8b2761223fc248e4e4b3a to your computer and use it in GitHub Desktop.
BASH: Variable substitution on user input
#!/bin/bash
set -e
name=
_prompt() {
local message="$1"
local -n input="$2"
while [ -z $input ]; do
printf "$message\n"
read input
done
echo $input
}
_prompt "What is your name?" name
echo "Your name is ${name}!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment