Accessing and Modifying Environment Variables
Now that we understand what environment variables are and why they are important, let's dive into how to access and modify them in a Linux system.
Accessing Environment Variables
As mentioned earlier, you can use the echo command to display the value of a specific environment variable:
echo $HOME
This will output the value of the HOME environment variable, which typically represents the user's home directory.
You can also use the env command to list all the environment variables currently set in the system:
env
This will display a list of all the environment variables and their corresponding values.
Modifying Environment Variables
To set or modify an environment variable, you can use the export command:
export MY_VARIABLE="my value"
This will create a new environment variable named MY_VARIABLE and assign it the value "my value".
You can also use the export command to modify the value of an existing environment variable:
export PATH=$PATH:/path/to/new/directory
This will append the /path/to/new/directory to the existing value of the PATH environment variable.
To delete an environment variable, you can use the unset command:
unset MY_VARIABLE
This will remove the MY_VARIABLE environment variable from the system.
Remember that the changes made to environment variables using the export and unset commands are only temporary and will not persist across sessions. To make environment variable changes permanent, you need to modify the appropriate configuration files, which we'll cover in the next section.