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

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


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.


It's very easy ;)

env


It sounds like you want environment variables, so use export -p. The output (which consists of lines of the form export variable=value per POSIX) is quoted in such a way that it can be parsed by the shell. It's also sorted by variable name in most shells.

If you want all shell parameters (for your use case, this would be relevant only if the scripts were sourced rather than called as separate programs), use set (again, it's in POSIX, the output is properly quoted for reparsing, and it's sorted in most shells).