Applying the New Environment Variable
Once you have created a new environment variable, you can use it in your scripts, commands, or applications. Here are a few ways to apply the new environment variable:
Accessing the Variable
To access the value of the environment variable, you can use the $
symbol followed by the variable name. For example, if you created a variable named MY_VARIABLE
, you can access its value like this:
echo $MY_VARIABLE
This will output the value of the MY_VARIABLE
environment variable.
Using the Variable in Commands
You can also use the environment variable within commands or scripts. For example, you can use the variable in a cd
command to change the current working directory:
cd $MY_VARIABLE
This will change the current directory to the value of the MY_VARIABLE
environment variable.
Passing the Variable to Child Processes
When you run a command or script, the environment variables are passed down to any child processes or subshells. This means that the new environment variable will be available to any programs or scripts that are executed from the current shell session.
my_script.sh
In the above example, the my_script.sh
script will have access to the MY_VARIABLE
environment variable.
Verifying the Variable
To verify that the new environment variable is available and has the correct value, you can use the env
or printenv
commands:
env | grep MY_VARIABLE
printenv MY_VARIABLE
These commands will display the value of the MY_VARIABLE
environment variable.
By understanding how to create and apply new environment variables, you can customize your Linux environment and streamline your workflow.