LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Difference between "set" and "env"? (https://www.linuxquestions.org/questions/linux-newbie-8/difference-between-set-and-env-402963/)

jdupre 01-13-2006 12:56 PM

Difference between "set" and "env"?
 
When trying to output a list of all the environment variables, I notice that there is a difference between "set" and "env". An obvious difference is that "set" outputs quoted strings and "env" does not quote. But of more concern is that "env" omits some of the variables that "set" displays.

Why are some variables that are displayed with "set" not displayed with "env"?

Is there a particular method of creating an environment variable that prevents it from being passed to a new environment?

- Joe

druuna 01-13-2006 02:50 PM

Hi,

set:
Without options, the name and value of each shell variable are displayed in a format that can be reused as input. The output is sorted according to the current locale.

env:
A 'limited' execution environment with specific content.

For details on the content and ways to manipulate, take a look at man bash the COMMAND EXECUTION ENVIRONMENT and ENVIRONMENT section.

Hope this helps.

alar 01-13-2006 04:37 PM

And I always thought it was the difference between local and global...

Global environment variables are set by your login shell and new programs and shells inherit the environment of their parent shell.

Local shell variables are used only by that shell and are not passed on to other processes.

You can list your global environmental variables with the env or printenv commands. You unset them with the unsetenv (C shell) or unset (Bourne shell) commands.

To set a local shell variable use the set command with the syntax below for C shell. Without options set displays all the local variables.


All times are GMT -5. The time now is 03:47 AM.