The shell that Linux used in the first place was Bourne, and then Linux released Bash, which is an enhanced version of Bourne, and most Linux systems now use Bash by default.

Bourne Shell Variables

Home and path are the two most commonly used bourne shell variables

HOME

Current user’s home directory.

1
echo $HOME
img

prints current user's home directory

PATH

Paths of binary files, which are runnable programs.

1
echo $PATH
img

prints the executable files' directories

Bash Variables

The number of environment variables in bash is so large that only a few commonly used ones are listed here:

BASH

Print the directory where bash is stored.

1
echo $BASH
img

prints current bash shell's directory

BASH_VERSION

Prints bash’s version

1
echo $BASH_VERSION
img

prints current bash shell's version

BASHPID

Current Bash’s process ID.

1
echo $BASHPID
img

prints current bash shell's process ID

GROUPS

Current user’s group IDs:

1
echo $GROUPS
img

prints current user's group ID

HISTFILE

The directory of history file:

1
echo $HISTFILE
img

prints the history file's location

HISTFILESIZE

The allowed lines contained in the history file:

1
echo $HISTFILESIZE
img

prints the history file's allowed lines

HISTSIZE

The allowed lines contained in the history list:

1
echo $HISTSIZE
img

prints the history's allowed lines

HOSTNAME

Current host’s name:

1
echo $HOSTNAME
img

prints the current host name

HOSTTYPE

Current machine type:

1
echo $HOSTTYPE
img

prints the current host type

LINENO

The line number that the current shell or script is running:

1
echo $LINENO
img

prints the current shell's current line number

MACHTYPE

The CPU architecture, company name, and type of the system which Bash is running:

1
echo $MACHTYPE
img

prints the current machine's type

OSTYPE

The operating system that Bash is running on:

1
echo $OSTYPE
img

prints the current operating system's type

PPID

The shell’s parent’s process ID:

1
echo $$    # get current shell's process ID
img

prints the current shell's process ID

Switch to a new shell:

1
bash

Check parent shell’s process ID:

1
echo $PPID
img

prints the current shell's parent shell ID

RANDOM

Generate a random integer number between 0 and 32767

1
echo $RANDOM
img

prints a random number between 0 and 32767

SECONDS

The number of seconds since shell started:

1
echo $SECONDS
img

prints the seconds since shell started

SHELL

The full path of the shell we are using

1
echo $SHELL
img

prints the bash shell's location

SHLVL

The deep level of the current shell, every time a new instance of bash is started, the variable incremented by one:

1
echo $SHLVL
img

prints the current bash shell's deep level

Switch to a new bash, this starts a new bash instance:

1
bash

Check current bash’s deep level:

1
echo $SHLVL
img

prints the current bash shell's deep level

UID

The user ID of the current user:

1
echo $UID
img

prints the current user's ID

References 5.1 Bourne Shell Variables, 5.2 Bash Variables

Buy me a coffeeBuy me a coffee