I have a function in bash that get param a string, for example:
MYSQL_DATABASE then I want in my file to create a var named VAR_MYSQL_DATABASE but I can`t get the value.
create_var()
{
read -p "Enter $1 : " VAR_$1
printf VAR_$1 // print VAR_MYSQL_DATABASE_NAME instead what I typed, so how do I get the value?
if [[ -z VAR_$1 ]]; then
printf '%s\n' "No input entered. Enter $1"
create_entry $1
fi
}
create_var "MYSQL_DATABASE_NAME"
MYSQL_DATABASE_NAMEand set a variable in the bash script with the name. The idea is that I have to ask 15 variables and because of this I made this function to be dry. If I use this lineread -p "Enter MYSQL_USER_NAME : " MYSQL_DATABASE_NAMEall works.