Declaration Mechanism: Internal Variables
Learn how to work with internal Bash variables.
Internal variables
We can declare variables for our own purposes. Bash also can do that. These variables are called internal or shell variables. We can change values for some of them.
Internal variables solve two tasks:
-
They pass information from the shell to the applications it runs.
-
They store the current state of the interpreter.
Groups of internal variables
There are two groups of internal variables:
-
Bourne Shell variables
-
Bash variables
Bourne Shell variables
Bourne Shell variables came from Bourne Shell. Bash needs this group for compatibility with the POSIX standard. The following table shows the frequently used variables of this group.
Name | Value |
---|---|
HOME |
The home directory of the current user. Bash uses this variable for tilde expansion and processing the cd call without parameters. |
IFS |
It contains a list of delimiter characters. The word splitting mechanism uses them to split the strings into words. The default delimiters are space, tab, and a line break. |
PATH |
It contains the list of paths where Bash looks for utilities and programs. Colons separate the paths in the list. |
PS1 |
It is a command prompt. The prompt can include control characters. Bash replaces them with specific values (for example, the current user’s name). |
SHELLOPTS |
The list of shell options. They change the operating mode of the interpreter. Colons separate the options in the list. |
Get hands-on with 1200+ tech skills courses.