mirror of https://github.com/tLDP/LDP
24 lines
451 B
Bash
24 lines
451 B
Bash
#!/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
|