Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix shell script - printing all the variables available in the scope

Tags:

shell

unix

Is there any way to find out the variables available in the scope of the shell script.

the scenario is like this, we are using some third party tools and we can customize the output with creating shell scripts with a particular naming convention. we know that certain parameters are being passed to our custom shell scripts but we want to know what else is being passed.

thanks.

like image 430
Mahes Avatar asked Dec 08 '22 01:12

Mahes


2 Answers

The command is set

From the bash manual page

set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
    Without options, the name and value of each shell variable are displayed in a
    format that can be reused  as  input.

Do not confuse this with env which will print out the values of environment variables not shell variables. shell variables can be marked for automatic export into the environment of subsequent child processes using the export command.

scope as a programming term, only really applies to shell variables - commands like typeset and local can be used in some shells (ksh and bash) to allow the use of scoped shell variables within functions. environment variables are global to a instance of a processes.

like image 184
Beano Avatar answered Dec 28 '22 22:12

Beano


It's very easy ;)

env
like image 20
Wolph Avatar answered Dec 28 '22 22:12

Wolph