Contents

System Variables

Created and maintained by Linuxbash shell itself. This type of variable (with the exception of auto_resume and histchars) is defined in CAPITAL LETTERS. You can configure aspects of the shell by modifying system variables such as PS1, PATH, LANG,HISTSIZE,and DISPLAY etc.

View All System Variables

To see all system variables, type the following command at a console / terminal:

The number of commands to remember in the command history. The default value is 500.

echo $HISTSIZE

HOME

The home directory of the current user.

echo $HOME

IFS

The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command. The default value is <space><tab><newline>.

echo $IFS

LANG

Used to determine the locale category for any category not specifically selected with a variable starting with LC_.

echo $LANG

PATH

The search path for commands. It is a colon-separated list of directories in which the shell looks for commands.

echo $PATH

PS1

Your prompt settings.

echo $PS1

TMOUT

The default timeout for the read builtin command. Also in an interactive shell, the value is interpreted as the number of seconds to wait for input after issuing the command. If not input provided it will logout user.

echo $TMOUT

TERM

Your login terminal type.

echo $TERMexport TERM=vt100

SHELL

Set path to login shell.

echo $SHELL

DISPLAY

Set X display name

echo $DISPLAYexport DISPLAY=:0.1

EDITOR

Set name of default text editor.

export EDITOR=/usr/bin/vim

Note you may add above variable (export command) to the initialization file located in the home directory of your account such as ~/.bash_profile.

How Do I Display The Value Of a Variable?

Use echo command to display variable value. To display the program search path, type:

echo"$PATH"

To display your prompt setting, type:

echo"$PS1"

All variable names must be prefixed with $ symbol, and the entire construct should be enclosed in quotes. Try the following example to display the value of a variable without using $ prefix:

echo"HOME"

To display the value of a variable with echo $HOME:

echo"$HOME"

You must use $ followed by variable name to print a variable's contents.

The variable name may also be enclosed in braces:

echo"${HOME}"

This is useful when the variable name is followed by a character that could be part of a variable name:

echo"${HOME}work"

Say hello to printf

The printf command is just like echo command and is available under various versions of UNIX operating systems. It is a good idea to use printf if portability is a major concern for you. The syntax is as follows:

printf"$VARIABLE_NAME\n"printf"String %s"$VARIABLE_NAMEprintf"Signed Decimal Number %d"$VARIABLE_NAMEprintf"Floating Point Number %f"$VARIABLE_NAME

To display the program search path, type:

printf"$PATH\n"

OR

printf"The path is set to %s\n"$PATH

Sample outputs:

The path is set to /home/vivek/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

User Defined Variables

Created and maintained by user. This type of variable defined may use any valid variable name, but it is good practice to avoid all uppercase names as many are used by the shell.