What does the export team do?

I'm a little new to Linux, and I accidentally run some commands blindly to get everything done. I thought that it would not be a waste of time asking such questions, as new people will regularly know about it.

I recently started working with jenkins, and then I had to use this export command to run the jenkins military archive. Therefore, I needed to know what the 'export' command does, and why we need to run this command when jenkins starts (after the jenkins house is installed).

Thank!

+67
unix shell command environment-variables
Dec 10 '12 at 5:00
source share
3 answers

export in sh and related shells (e.g. bash ), puts the environment variable that will be exported to child processes, so that the child inherits them.

export defined in POSIX :

The shell should provide the export attribute to the variables corresponding to the specified names, which will lead to the fact that they will be in the environment of subsequent commands. If the name of the variable is followed by word = word, then the value of this variable should be set to the word.

+84
Dec 10
source share

I assume that you are coming from windows. So I will compare them (I am also new to Linux). I found the user's response to my comment to be helpful in sorting out.

On Windows, a variable can be constant or not. The term "environment variable" includes the variable set on the cmd command line with the SET command, and also when the variable is set in the Windows GUI, therefore it is installed in the registry and becomes visible in new cmd windows. for example, the documentation for the sed command in the windows https://technet.microsoft.com/en-us/library/bb490998.aspx "Displays, sets, or deletes environment variables. Used without parameters, sets the current environment settings." On Linux, a set does not display environment variables; it displays shell variables that it does not call / does not refer to as environment variables. In addition, Linux does not use the set to set variables (in addition to the positional parameters and shell parameters, which I explain as a note at the end), only to display them, and even then only to display shell variables. Windows uses a set for configuration and display, for example. set a = 5, linux - no.

On Linux, I think you can make a script that sets variables at boot, for example. /etc/profile or /etc/.bashrc , but otherwise they are not constant. They are stored in RAM.

On Linux, there is a distinction between shell variables and environment variables. On Linux, shell variables are found only in the current shell, and environment variables are in this shell and all child shells.

You can view shell variables using the set command (although note that, unlike windows, variables are not set on Linux using the set command).

set -o posix; set set -o posix; set (doing this set -o posix first, helps not to display too many unnecessary things). Therefore, set displays shell variables.

You can view environment variables using the env command

shell variables are set, for example, just a=5

environment variables are set with export; export also sets a shell variable

Here you see the zzz shell variable with zzz = 5, and its view is displayed when set run, but does not appear as an environment variable.

Here we see yyy set with export, so this is an environment variable. And you will see that this is displayed both in shell variables and in environment variables

 $ zzz=5 $ set | grep zzz zzz=5 $ env | grep zzz $ export yyy=5 $ set | grep yyy yyy=5 $ env | grep yyy yyy=5 $ 

other useful topics

https://unix.stackexchange.com/questions/176001/how-can-i-list-all-shell-variables

https://askubuntu.com/questions/26318/environment-variable-vs-shell-variable-whats-the-difference

Note. One point that clarifies a little and corrects to some extent what I wrote is that in linux bash, “set” can be used to set “positional parameters” and “shell parameters / attributes”, and technically both of them are variables, although the manual pages may not describe them as such. But still, as already mentioned, set will not set shell variables or environment variables). If you execute set asdf , then it sets $ 1 to asdf, and if you do echo $1 , you see asdf. If you do set a=5 , it will not set the variable a to 5. It will set the positional parameter $ 1 to the string "a = 5". Therefore, if you have ever seen the set a = 5 in linux, this is probably a mistake if someone really did not want this line a = 5, in $ 1. Another thing that the linux suite can set is shell options / attributes. If you installed - you see a list of them. And you can do, for example, set -o verbose , off to enable verbose (btw is disabled by default, but that doesn't make any difference to this). Or you can do set +o verbose to disable verbose text. Windows does not have such use for the set command.

+16
Jul 16 '15 at 19:19
source share

In simple terms, environment variables are set when a new shell session is opened. at any time, if you change any of the variable values, the shell is not able to select this change. this means that your changes become effective in new shell sessions. the export command, on the other hand, provides the ability to update the current shell session about the change you made to the exported variable. You do not need to wait until the new shell session uses the value of the variable that you changed.

+2
May 16 '15 at
source share



All Articles