Linux Training – Using Shell Environment Variables – Administration Commands Training

0
6

The Linux Shell Environment and the Environment Variables

A Linux terminal or a terminal emulation window gives you access to the “bash shell environment” so you can run Linux commands. And there are several “environment variables” that you can work with when using Linux scripts, programs, and commands, and to view system information.

You run the env (environment) command without any options to see the environment for your current user.

Run this Linux command now to see your current environment variable settings.

Linux Commands Training Tips: The Linux System Administration concepts and commands covered here apply to ALL other Linux distributions, including: Debian, Ubuntu, Slackware, SUSE, openSUSE, Red Hat, Fedora, Edubuntu – and Kubuntu.

Bash Shell Environment Variable Examples

Here are some examples of common Linux environment variables.

SHELL

This variable holds the name of the current Linux shell, which is most commonly the “bash” shell.

USER

Contains the name of the currently logged in user.

HOME

Holds the full directory path to the current user’s home directory.

For example, if you’re working as a non-root user, the path will be /home/username, where username will be the name you logged in with. If you logged in as bhatch, then the path will be /home/bhatch.

As another example, if you’re working as the root user, then the path will simply be /root.

PS1

Used to contain the settings for displaying the current Linux command line prompt.

For example, you can use this variable to specify how the prompt looks, such as whether to show the current directory and the character that appears at the far right of the prompt.

LOGNAME

Shows the currently logged in user name.

Viewing Environmet Variables with the Linux echo Command

You can run the echo command and prefix a variable with a $ (dollar sign) to see the contents of a variable.

Run the echo command below to see your current user name.

$ echo $USER

Press the up arrow key to repeat the last command and press backspace to remove the variable and replace it with the variable that shows the path to the home directory for the current user.

Now do the same as above with the other environment variables described above.

Source

Leave a Reply