Bash Passing an indirect reference to a function
Passing an indirect reference to a function
#!/bin/bash
# ind-func.sh: Passing an indirect reference to a function.
echo_var ()
{
echo "$1"
}
message=Hello
Hello=Goodbye
echo_var "$message" # Hello
# Now, let's pass an indirect reference to the function.
echo_var "${!message}" # Goodbye
echo "-------------"
# What happens if we change the contents of "hello" variable?
Hello="Hello, again!"
echo_var "$message" # Hello
echo_var "${!message}" # Hello, again!
exit 0