Bash variables: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== 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...") |
mNo edit summary |
||
Line 10: | Line 10: | ||
declare -xp | declare -xp | ||
</pre> | </pre> | ||
An alternate command that will also give nice and parsable results | |||
<pre> | |||
compgen -v | while read line; do echo $line=${!line};done | |||
</pre> | |||
[[Category:Bash]] | [[Category:Bash]] |
Revision as of 11:27, 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
compgen -v | while read line; do echo $line=${!line};done