I’ve been looking for better way of doing it recently. Associative array sounded like overkill for me. Look what I found:
suffix=bzz
declare prefix_$suffix=mystr
…and then…
varname=prefix_$suffix
echo ${!varname}
More Related Contents:
- Why does shell ignore quoting characters in arguments passed to it through variables? [duplicate]
- Brace expansion with variable? [duplicate]
- What is the meaning of the ${0##…} syntax with variable, braces and hash character in bash?
- What is the difference between ${var}, “$var”, and “${var}” in the Bash shell?
- osascript using bash variable with a space
- Why should there be spaces around ‘[‘ and ‘]’ in Bash?
- Expansion of variables inside single quotes in a command in Bash
- How to use double or single brackets, parentheses, curly braces
- Capturing multiple line output into a Bash variable
- What is the benefit of using $() instead of backticks in shell scripts? [duplicate]
- Bash – variable variables [duplicate]
- What is the purpose of “&&” in a shell command?
- Test for non-zero length string in Bash: [ -n “$var” ] or [ “$var” ]
- Using variables inside a bash heredoc
- Ternary operator (?:) in Bash
- How to remove a newline from a string in Bash
- Compound ‘if’ statements with multiple expressions in Bash
- Why source command doesn’t work with process substitution in bash 3.2?
- Using the && operator in an if statement
- bash: $[] vs. $(())
- Is it possible to build variable names from other variables in bash? [duplicate]
- Bash indirect variable referencing
- How to modify a global variable within a function in bash?
- bash background process modify global variable
- Expand variables in sed
- bash piping prevents global variable assignment
- Rsync syntax error when run from bash script
- Left side of pipe is the subshell?
- Loop over array, preventing wildcard expansion (*)
- What is the proper way to test a Bash function’s return value?