And why is an export
needed? Where is it exporting to?
The easiest way to set environment variables in Bash is to use the “export” keyword followed by the variable name, an equal sign and the value to be assigned to the environment variable.
Environment variables exist to enhance and to standardize your shell environment on Linux systems. There are standard environment variables that the system sets up for you, but you can also set up your own environment variables, or optionally change the default ones to meet your needs.
Environment variables are special variables (like $HOME ) that contain information about your login session. They're stored for the system shell to use when executing commands. They exist whether you're using Linux, Mac, or Windows. Many of these variables are set by default during installation or user creation.
Exported variables are passed on to new processes invoked.
Try setting A=1
, then invoking a new shell by entering "bash", then echo $A
- an empty line.
Do the same, but then export A=1
, invoke a new shell, then echo $A
- voila!
edit on the technical side, and looking at your question, B=1 doesn't actually set an environment variable. To get the real environment of your shell (in linux), try
$ xargs -n 1 -0 echo < /proc/$$/environ
which differs from the output of export
. And as a sidenote, this question touches on the internals of bash and its environment handling.
The PS1
environment variable is pre-defined by the bash
shell; consequently, it doesn't need to be exported, merely set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With