bash indirection and/or nameref
Comming late on this question, and because no other answer tell about nameref...
Using ${!var} indirection syntax:
~$ someVariable='Some content'
~$ var=someVariable
~$ echo $var
someVariable
~$ echo ${!var}
Some content
Using namref (declare -n) syntax
By using nameref you could not only show content of variable, but you can populate variable and get or set attributes.
~$ someVariable='Some content'
~$ declare -n var=someVariable
~$ echo $var
Some content
This syntax is usefull for functions:
function showVarDetail() {
local -n var=$1
printf 'Variable \47\44%s\47 is %d len, has [%s] flags and contain: %q\n' \
"$1" "${#var}" "${var@a}" "$var"
}
(Nota: This function is only a sample. This won't expand correctly arrays and associative arrays!)
Then
~$ someVar='Hello world!'
~$ showVarDetail someVar
Variable '$someVar' is 12 len, has [] flags and contain: Hello\ world\!
~$ declare -r PI=3.14159265358979323844
~$ showVarDetail PI
Variable '$PI' is 22 len, has [r] flags and contain: 3.14159265358979323844
Populating variable values using nameref
This could work in both ways!
Here is a little sample function to run with two variable names as arguments. First variable should contain a string and second variable will be populated by 1st character of 1st variable content, then 1st variable content will be shifted by 1 character:
shift1char <variable string source> <variable target>
shift1char () {
local -n srcStr=$1 tgtVar=$2;
tgtVar=${srcStr::1} srcStr=${srcStr:1}
}
Then
~$ someVar='Hello world!'
~$ shift1char someVar someChar
~$ showVarDetail someVar
Variable '$someVar' is 11 len, has [] flags and contain: ello\ world\!
~$ showVarDetail someChar
Variable '$someChar' is 1 len, has [] flags and contain: H