Useful variables in Linux, and how they can be utilised/customised. Environment variables are passed to any command/program created by the current shell and are typically denoted in ALL CAPS. Local variables are only available in current shell and are declared in lower case. The echo command can be used to display a variable by prefixing it with $. It may be helpful to delimit variables using {} to make them easier to read. Before modifying an environment variable, it is advisable to back it up to a local variable. Some modifications need to be applied in an initialisation file to become persistent.

echo ${PATH}
#displays the PATH environment variable

#backs up environment variable PATH to local variable path


Can be used to denote exit status of last command – an integer between 0 and 255 with 0 being successful.

#following grep mrnoobot /etc/passwd
echo $?
#displays exit status - eg 0 for success (ie found), 1 for fail -not found, 2 for fail - permission denied and so on.


Variable that contains customisation features for history.

#ignore duplicate commands entered consecutively
#ignore any command preceded by a space
#combines ignorespace and ignoredups
#do not store duplicate commands (only the most recent is retained)
#chaining customisation - this provides ignorespace and erasedups


Provides a path in which the command history is kept – by default contains maximum of 500 entries.


Determines how many commands to write to ${HISTFILE} when shell is closed. If ${HISTFILESIZE} and ${HISTSIZE} are different, the lower value will be written.


Specifies which commands should be ignored for writing to history.

#ignores the ls, cd and history commands including all trailing syntax, as well as the exit command.


Defines how many commands to keep in memory for each shell.


Contains path to users home directory.


The PATH environment variable is a list of directories that are searched for commands entered by the user. The PATH variable can be modified; this could be used inappropriately by naming a malicious script after a popular command and including the path in the PATH variable.

#appends the directory /home/mrnoobot to the PATH variable

It is generally more accepted to move the command into an existing PATH directory. When searching for a command, the system moves through the PATH variable from left to right and uses the first matching command it finds (hence the vulnerability described above). It is therefore important to check to see if a command already exists with that name (using type command) before moving files.


Prompt variable.

PS1 = 'Noobot> '
#Changes command prompt to Noobot>

Special characters (preceded by \)
w #display full path
W #display relative path

Others are listed under:
man bash


Timezone variable

export TZ=America/New_York
#set timezone to America New York time (EST). Timezone must be available.