I am running Red Hat Linux Enterprise 5; I am always using the export command to set environment variables.
Are there any other ways to set environment variables and what are the advantages/disadvantages of them?
This is an excerpt from the Bash man page:
If you only need the variable in the current environment, it's not necessary to use export.
Without export: current environment only. With export: current environment and child environments.
Here's a demonstration of the affect of export on availability of a variable in a child environment and that changes in the child environment don't affect the parent:
After the first echo (
After the line that starts "
In the "script" the values of the variable are changed. It now outputs those new values.
Once the "script" is finished, execution returns to the parent environment (the command line in this case). After the last echo, you see the original values because the changes made in the child environment do not affect the parent.
You say that
By the way you worded that, it sounds like you are really trying to ask how do you make an environmental variable persists. To do that would require you to place your
This will work for all login shells where bash is the shell of choice. For non login shells, you need to use .bashrc. I have no insights to offer for other shells :D
export is the most straightforward way to do it, so why not leave it at that?
You can also do something like this:
output in English.
output in Polish (if avaliable).
In the past in sh you couldn't do export VAL=val. You had to