AndySW
AndySW

Reputation: 27

Is there a command to dump local variables in a bash script?

I have many scripts where I make use variables within the scripts. While the script is running, can I issue a command within the script to dump all of the variables and their values?

Upvotes: 1

Views: 1832

Answers (2)

beny23
beny23

Reputation: 35068

If you are after a way of helping you debug your script, you could put

set -x

At the beginning of your script that will display command traces including how your variables are used.

Upvotes: 5

alvits
alvits

Reputation: 6768

The command env on its own should display all the variables.

The builtin command set on its own will also dump the variables.

Note that inherited variables will also be dumped.

Upvotes: 4

Related Questions