Environment Variables and How to Print Them in Linux

This article will show you how to list and print environment variables in the Linux terminal. You can use this information to debug or figure out what is going on with your system when something isn’t working quite right.

Environment variables are parameters that affect the shell or any other program’s behaviour. These are also called global or internal variables because they are not limited to a specific shell. They are an essential part of the operating system. They may be temporary or permanent, depending on how the user wants them to be.

The biggest advantage of an environment variable is user-friendliness. It should also include resources that can be used for all users in a system. For instance, the HOME variable defines the directory where a user’s default configuration files should exist first before any other files.

Print Environment Variables

The first step is just getting a listing of all of the current variables that are defined on your computer using the command below.

env

The output should list all the existing variables as shown below.

HOME=/home/username
SHELL=/bin/bash

Print a single variable

In order to see a single environment variable at a time, type the following command:

echo $HOME

The output will contain your home directory.


Posted

in

, ,

by