Variables can also be made part of your environment, which means that their values are visible to any programs or shell scripts that you execute. When you set a variable initially, it is by default not part of your environment. In order to make it so, you must export the variable name in one of two ways, either as two separate commands or one combined command:
$ COLOR=tangelo $ export COLOR $ export COLOR=tangelo
In addition, while you can view the values of all of your variables with the set command, you can list just your environment variables with the env command (your environment variables will always be a subset of your entire set of shell variables).
Tip | |
---|---|
Once a variable has been exported in a login session, its value can be changed later without having to be exported again. Once a variable has been added to the environment, it remains part of the environment for the rest of that login session. |
Tip | |
---|---|
You can set and export one or more variables for the duration of just a single command with the example syntax: $ COLOR=tangelo command |
Warning | |
---|---|
Installing new software often involves setting some software-specific customization variables so that the users can access and execute the program properly. Almost always, these app-specific variables have to be exported to the user's environment, but the documentation may refer only to the setting of one or more "environment" variables, without actually using the word "export". Any time you see a reference to a variable being made part of the environment, it's a safe bet that it should be exported, whether you see the word "export" or not. |