Environment variables are placeholders for data that can change. Each user has environment variables with different values to define his or her working environment. For example, each user typically has its own home directory, so the content of the HOME environment variable is different for each user on the system. A program that needs to know the user’s home directory can refer to theHOME variable to obtain this information.
To see the environment variables on your system, type env:
To set an environment variable manually, use an equal-sign assignment operator. If you want your variable to be available to programs you launch from your shell use the export command:
In the example above we have assigned the value “example” to the variable VAR1. For brevity, you can comibne these two commands in one: export VAR1=example.
To refer to an environment variable, you must put special the dollar sign ($) in front of the variable name:
In the example above we have used the echo command to display the content of the variable VAR1.
Setting an environment variable as just described sets it permanently only for the current shell. For example, if we open another terminal window, the variable VAR1 will not be set:
To make environment variables permanent you need to set them in a global or local bash startup script.
Post a Comment