开发者

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

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 tha开发者_高级运维t certain parameters are being passed to our custom shell scripts but we want to know what else is being passed.

thanks.


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).


This may be really simplistic but...

grep = <your script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜