LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Silly Shell Question (https://www.linuxquestions.org/questions/linux-newbie-8/silly-shell-question-672838/)

paragkalra 09-28-2008 01:26 AM

Silly Shell Question
 
Quote:

Local Variable Definition: A variable declared as local is one that is visible only within the block of code in which it appears.
Quote:

Global Variable Definition: Global environment variables are visible from the shell session, and any child processes that the shell spawns.
Keeping these definitions in mind what is the difference between global variables displayed by "evn" command and local variables displayed by "set" command?

unSpawn 09-28-2008 03:27 AM

Quote:

Originally Posted by paragkalra (Post 3293909)
Keeping these definitions in mind what is the difference between global variables displayed by "evn" command and local variables displayed by "set" command?

You could ask yourself what the origin of 'env' and 'set' is? With the distinction that "local" in such cases usually refers to functions, subshells and such, in a generic GNU/Linux layout 'env' is a binary part of coreutils (which) and shows vars set for or by the login shell and what gets sourced automagically. Some vars of which are immutable by generic unprivileged users and whose scope is systemwide (UID, locale settings, etc). In a shell like Bash 'set' is a built-in (type) displaying variables inherited from the login shell plus those the shell emits, needs, recognises or understands them itself from sourcing.

I'm sure somebody else has got a more clean definition.

john test 09-28-2008 11:31 AM

unSpawn has it right, but just to look at the difference you could try opening two xterm windows and doing "set" in one and "env" in the other.
Side by side comparison will show the inherited variables and the additional info in "set"


All times are GMT -5. The time now is 05:16 AM.