GNU/Linux >> LINUX-Kenntnisse >  >> Linux

Was soll der export-Befehl unter Linux bewirken?

Exportieren Sie eine Shell-Variable als Umgebungsvariable.


Hier ist ein Beispiel, um das Verhalten zu demonstrieren.

$ # set testvar to be a value
$ testvar=asdf
$ # demonstrate that it is set in the current shell
$ echo $testvar
$ # create a bash subprocess and examine the environment.
$ bash -c "export | grep 'testvar'"

$ bash -c 'echo $testvar'

$ # export testvar and set it to the a value of foo
$ export testvar=foo
$ # create a bash subprocess and examine the environment.
$ bash -c "export | grep 'testvar'"
declare -x testvar="foo"
$ bash -c 'echo $testvar'
foo
$ # mark testvar to not be exported
$ export -n testvar
$ bash -c "export | grep 'testvar'"

$ bash -c 'echo $testvar'

Sie werden das ohne export bemerken Der neu erstellte Bash-Prozess konnte testvar nicht erkennen . Wenn testvar exportiert wurde, konnte der neue Prozess testvar sehen .


Bitte sehen Sie sich dieses Bash-by-Beispiel-Tutorial von IBM an. Es enthält sogar ein Beispiel für die Verwendung von export .


Linux
  1. Der Befehl locate unter Linux

  2. Was ist das Windows-Analogon des Linux-Überwachungsbefehls?

  3. Was ist das Äquivalent zum Linux-Dateibefehl für Windows?

  4. Was ist der Unterschied zwischen &> und >&in bash?

  5. Was ist das Äquivalent von Linux's ~ (Tilde) in Windows?

Was ist die Shell unter Linux?

Der Timer-Befehl in Linux

So verwenden Sie den Linux-Exportbefehl im Computeralltag

Exportbefehl unter Linux

Was ist der Kill-Befehl in Linux?

Der Linux-Move-Befehl:Erklärt &leicht gemacht!