Files
pure-bash-bible/manuscript/chapter6.txt
2019-01-19 18:04:22 +08:00

32 lines
441 B
Plaintext

# VARIABLES
## Assign and access a variable using a variable
```shell
$ hello_world="value"
# Create the variable name.
$ var="world"
$ ref="hello_$var"
# Print the value of the variable name stored in 'hello_$var'.
$ printf '%s\n' "${!ref}"
value
```
Alternatively, on `bash` 4.3+:
```shell
$ hello_world="value"
$ var="world"
# Declare a nameref.
$ declare -n ref=hello_$var
$ printf '%s\n' "$ref"
value
```
<!-- CHAPTER END -->