13. Bourne and Bash Shells' Environment Variables
Contents
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.
|
|

prints current user's home directory
PATH
Paths of binary files, which are runnable programs.
|
|

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.
|
|

prints current bash shell's directory
BASH_VERSION
Prints bash’s version
|
|

prints current bash shell's version
BASHPID
Current Bash’s process ID.
|
|

prints current bash shell's process ID
GROUPS
Current user’s group IDs:
|
|

prints current user's group ID
HISTFILE
The directory of history file:
|
|

prints the history file's location
HISTFILESIZE
The allowed lines contained in the history file:
|
|

prints the history file's allowed lines
HISTSIZE
The allowed lines contained in the history list:
|
|

prints the history's allowed lines
HOSTNAME
Current host’s name:
|
|

prints the current host name
HOSTTYPE
Current machine type:
|
|

prints the current host type
LINENO
The line number that the current shell or script is running:
|
|

prints the current shell's current line number
MACHTYPE
The CPU architecture, company name, and type of the system which Bash is running:
|
|

prints the current machine's type
OSTYPE
The operating system that Bash is running on:
|
|

prints the current operating system's type
PPID
The shell’s parent’s process ID:
|
|

prints the current shell's process ID
Switch to a new shell:
|
|
Check parent shell’s process ID:
|
|

prints the current shell's parent shell ID
RANDOM
Generate a random integer number between 0 and 32767
|
|

prints a random number between 0 and 32767
SECONDS
The number of seconds since shell started:
|
|

prints the seconds since shell started
SHELL
The full path of the shell we are using
|
|

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:
|
|

prints the current bash shell's deep level
Switch to a new bash, this starts a new bash instance:
|
|
Check current bash’s deep level:
|
|

prints the current bash shell's deep level
UID
The user ID of the current user:
|
|

prints the current user's ID
References 5.1 Bourne Shell Variables, 5.2 Bash Variables
Author Dong Chen
LastMod Thu Feb 14 2019