>> [MUSIC]
>> As the name implies,
environment variables set a number of
variables for your shell environment.
Environment variables are important because applications,
command line tools and shell scripts
use them to determine their configuration.
Knowing how to view, create,
and modify environment variables is
a must if you were to learn the ways of the terminal.
The very first command that you should learn when
dealing with environment variables is the ENV command.
To issue the ENV command just type ENV and then enter,
and you will be presented with all
of the environment variables that are currently available.
If you look at these,
you'll notice that there is the name of the variable on the left,
and then an equal sign followed by the value.
If we scroll to the very top here,
there should be an environment variable called shell=/bin/bash,
and that is the location of the bash binary.
Now, if we wanted to see just a single environment variable,
we can use the echo command.
If we type echo followed
by the name of
the environment variable now this has to begin with a dollar sign
because it already exists and we're not creating
the environment variable so we declare that it's of a variable,
and how you do that is by putting a dollar sign in front of it.
Shell was the name of the environment variable,
and if I hit "Enter" here,
I will get back just the value of that environment variable.
Shell is a name.
It's being declared as a variable because at the dollar sign,
and then it's returning back to me the value of that variable.
Now the next thing that we want to look at are a couple of
useful environment variables that come preloaded.
If we look at home,
home is the location or the home directory of the current user.
Then echo is who the current user is.
These are useful when you're
on a system and you're logged in and you don't
know which user or directory you should
be putting things or where your profile is.
Now another very useful environment variable is the path variable.
If we take a look at the path variable,
we'll see a number of locations separated by a colon.
What these are,
are locations to executables.
A lot of times when you install
a new program and you can't just type
the name of the program say it's notion, or notation.
Say maybe it's a new command line tool called Notation,
if I don't have that inside my path variable,
the shell isn't going to know where to execute that from,
and that would result in me having
to give the full path to the binary.
That is an environment variable that you
will want to become familiar with
over time where you want to append or
remove different binaries from that variable,
because it's giving you the location of where
that binary is located.
Now that you've learned how to view environment variables,
the next thing that you might want to know is how to create them.
The command to create environment variables is the export command.
If we take a look at the help,
we can see how we can use it.
It takes a name followed by an equal sign and then a value.
If I type export new var equals value,
this will create a new environment
variable in my current session,
and I can view that with the echo command, new var.
I can also see it in the output of the ENV command.
Now, VSCode has a new future where I can search this text.
If I wanted to search for new var,
I can see where I executed the export command and the echo.
But down here I can also search
the output of the ENV command and right there as many value.
One important detail of that environment
variable that I just created is that,
it's only available in this current session.
If I open up another bash prompt,
and I type eco new var, it doesn't exist.
That begs to ask the question,
how do you persist environment variables across sessions?
And how do those environment variables
they return to us when we issued the ENV command.
The answer to that question is what bash calls startup files.
There are a number of locations
where these startup files can exist,
but two worth mentioning are the global configuration
which is located under ETC, profile.
And if you were to make changes to this particular file,
it would affect every user logged in the machine or
their bash session for every user logged in the machine.
Then the other one is
the.profile which exists underneath the user's home directory.
If we ls-a, the home directory of this VSCode user,
there is a profile that was created by this Codespace that
has a number of options in there that is configuring this session.
Another one inside the user's profile is the Bash RC.
Each of those files are loaded into
the session when you start a new prompt or a new bash session.
If you were to put the export command inside of those files,
it would be automatically loaded and shared
and persisted across your different sessions.
>> [MUSIC]