Bash variables: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
|||
Line 11: | Line 11: | ||
</pre> | </pre> | ||
An alternate command that will also give nice and parsable results | An alternate command that will also give nice and parsable results. This is quite nice, as the loop itself will pull the values that compgen -v gave as just var names. | ||
<pre> | <pre> | ||
compgen -v | while read line; do echo $line=${!line};done | compgen -v | while read line; do echo $line=${!line};done |
Revision as of 11:29, 26 October 2022
Finding defined variables
Assuming you have done something like foo="bar" at your bash prompt it is not always clear how to echo ALL the defined variables back from your bash session. The following is a good way to get that information when needed. This can also be useful for debugging scripts that you are in the process of building out.
declare -p
If you only want the environment variables, and do not want to use env for some reason
declare -xp
An alternate command that will also give nice and parsable results. This is quite nice, as the loop itself will pull the values that compgen -v gave as just var names.
compgen -v | while read line; do echo $line=${!line};done