▲ | Grimeton 3 days ago | |
There are no objects in bash. There are indexed and associative arrays and both can be iterated over like so:
or with the help of the keys:
If you want to dump the data of any variable you can just use declare -p
and you get something like this:
What you can do, if you have a set of variables and you want them to be "dumped", is this:Let's "dump" all variables that start with "BASH":
Or one could do something like this:
But the declare option is much more reliable as you don't have to test for the variable's type. | ||
▲ | westurner 3 days ago | parent [-] | |
Bash has associative arrays, but just POSIX shells like ash do not have associative arrays. And, POSIX shell can only shift and unshift on the $@ array; so it would be necessary to implement hashmaps or associative arrays with shell string methods and/or eval. |