[opensuse] How to get list of variables
How do I get a complete listing of available variables in bash? -- ---Bryen--- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Mon, 2007-10-29 at 21:08 +0000, Thomas Hertweck wrote:
Bryen wrote:
How do I get a complete listing of available variables in bash?
Chapter "PARAMETERS", section "Shell Variables" in "man bash".
Th.
Or page 290 of O'Reilly's "Learning the bash shell" -- Regards, Aniruddha Please adhere to the OpenSUSE_mailing_list_netiquette http://en.opensuse.org/OpenSUSE_mailing_list_netiquette -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Monday 29 October 2007 13:59, Bryen wrote:
How do I get a complete listing of available variables in bash?
Do you mean variables with built-in meanings? In which case, Thomas' answer is the right one, though "help variables" gives you a short list right in the shell. If you want to know which variables are currently defined, the "set" built-in command lists them. "help set" for a brief description or consult the man page for all the details. I use this shell procedure (defined in my .bashrc) to query local variables: vq () { set | egrep -e "$1" } This has to be a shell procedure since by definition local variables are not accessible in sub-shell and hence could not be displayed via a conventional script. And I use this counterpart to query environment variables: eq () { export | sed -n -e "/$1/ s/declare -x //p" } This one could be shell script, if you prefer.
-- ---Bryen---
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Randall R Schulz wrote:
[...]
I use this shell procedure (defined in my .bashrc) to query local variables:
vq () { set | egrep -e "$1" }
Isn't "set" also reporting functions etc.? I usually use "printenv" to query (environment) variables... Th. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Monday 29 October 2007 14:33, Thomas Hertweck wrote:
Randall R Schulz wrote:
[...]
I use this shell procedure (defined in my .bashrc) to query local variables:
vq () { set | egrep -e "$1" }
Isn't "set" also reporting functions etc.? I usually use "printenv" to query (environment) variables...
That's true (though I don't think there's anything left in the "etc." category besides local variables and function definitions), so if I query a name found in a function definition, I'll get spurious results. But it's usually pretty easy to spot and ignore them. But the point of "vq" (value query) vs. "eq" (environment query) is to be able to distinguish the two. The second function I gave is restricted to exported variables (which by definition excludes shell functions). And printenv is a standard command, thus requiring a(nother) fork / exec to invoke. Export doesn't, so it has lower overhead. It's of little real consequence, but some of us are still efficiency freaks...
Th.
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Randall R Schulz wrote:
On Monday 29 October 2007 14:33, Thomas Hertweck wrote:
Randall R Schulz wrote:
[...]
I use this shell procedure (defined in my .bashrc) to query local variables:
vq () { set | egrep -e "$1" } Isn't "set" also reporting functions etc.? I usually use "printenv" to query (environment) variables...
That's true (though I don't think there's anything left in the "etc." category besides local variables and function definitions), so if I query a name found in a function definition, I'll get spurious results. But it's usually pretty easy to spot and ignore them.
But the point of "vq" (value query) vs. "eq" (environment query) is to be able to distinguish the two. The second function I gave is restricted to exported variables (which by definition excludes shell functions).
And printenv is a standard command, thus requiring a(nother) fork / exec to invoke. Export doesn't, so it has lower overhead. It's of little real consequence, but some of us are still efficiency freaks...
But then you have to fork off the sed or grep command, and then do write(2) into and read(2) out of the pipe, so I'm not seeing any increased efficiency there when compared to env or printenv. Could it be that this was a hack from the late 70's early 80's that you've just become used to doing, and never re-evaluated whether it is still necessary (or even most efficient)? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (5)
-
Aaron Kulkis
-
Aniruddha
-
Bryen
-
Randall R Schulz
-
Thomas Hertweck