Created
June 9, 2019 00:22
-
-
Save jpcaparas/106e0d43c5f8b2761223fc248e4e4b3a to your computer and use it in GitHub Desktop.
BASH: Variable substitution on user input
This file contains hidden or 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
#!/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