An environment variable is a variable whose value is set outside of the program. In this shot, we will go through how to create and delete an environment variable using Bash.
We can create and delete the environment variables using the following syntax.
# create environment variable export variable_name # delete environment variable unset variable_name
The export
keyword will create the environment variable, while the unset
keyword will delete the environment variable.
Let's take a look at an example.
# display the environment variables echo "-> Displaying all environment variables before creating a new environment variable <-" env # create environment variable export PROD_URL = "https://educative.io" # display the environment variables echo -e "\n-> Displaying updated environment variables after creating a new environment variable <-" env # delete environment variable unset PROD_URL # display the environment variables echo -e "\n-> Displaying environment variables after deleting the new environment variable <-" env
In the above code snippet, we see the following:
env
.PROD_URL
using the command export
.env
. We can see that there's a new variable PROD_URL=https://educative.io
in the code output.PROD_URL
using the command unset
.env
.RELATED TAGS
CONTRIBUTOR
View all Courses