The Shell Environment
Shell·3 min read·Jan 1, 2025
In programming, a variable is a named container used to store data referred to as a value.
The shell environment, often abbreviated env, is a collection of variables in the form of name-value pairs.
It mostly contains information about your current shell session, which can be used by the shell itself or programs launched in your shell, in order to modify the way they run.
These variables often include information such as your username, the path of your home directory, the path to your shell, the path to your binaries, and so on.
The types of environment variables
Environment variables can be defined either by the operating system, users of the system, and sometimes, programs and scripts.
They can be local, which means that they are defined for the current shell session only and will be erased as soon as the shell is exited or the terminal is closed.
They can be user specific, which means that they are defined for a specific user in a configuration file that is loaded every time this user opens a shell.
They can be system wide, which means that they are available for every user of the system whenever a new shell session is started.
Common environment variables
The most common environment variables include:
-
USERwhich stores the username of the current user. -
HOMEwhich represents the user's home directory.
Unlock the CLI & Scripting with Bash module
Learn how to gain advanced control over the OS and automate complex routine tasks prone to manual errors with the CLI and Bash scripting.
You get immediate access to:
- 34 focused lessons across the CLI and Bash
- 4 real-world projects with commented solutions
- Ongoing updates to this bundle
- Lifetime access to this bundle