Pete's Linux Advent Calendar 2007

The 11th day

Bash Parameter Expansion

You know that with $VAR you get the value of the variable named VAR. You pass the variable by value. But you can also pass by reference. Use the exclamation point ! inside the variable. Here is an example scriptlet that prints the value of the given variable name:
#!/bin/bash
variable="$1"
echo the value of $variable is ${!variable}
Note with arrays it's different and involves the usage of eval.
Pete's Linux Advent Calendar 2007

Valid HTML 4.01!

Comments? send mail to pkruse@arcor.de my monogram