Some Common Variables

Some Common Variables

  • Configuration variables
    • PS1: Appearance of the bash prompt
    • HISTFILESIZE: Number of commands in bash history
    • PATH: Directories to look for executables in
    • EDITOR: Default text editor
  • Information variables
    • HOME: User’s home directory
    • EUID: User’s effective UID

The PS1 shell variable sets the prompt. The prompt can vary each time it is displayed by using special escaped sequences. For a complete list see the PROMPTING section of the bash man page. Some common escape sequences are:

\hShort hostname (not the fully qualified domain name)
\uuser name (useful if you have multiple accounts)
\wthe current working directory
\!the history number of the current command
\$show $ if you are a non-privileged user and a # if privileged user, useful if you sometimes become superuser.

Consider the following prompt setting where the quotes are important as they ensure a space between the prompt and command to be typed:

[user@stationX ~]$ PS1=\u@\h: \w <\!>\$ "
digby@kennel:/tmp <1067>$

The PATH environment variable determines the location and order of directories to be searched by the shell when a user wishes to execute a command. For instance, when a user issue the command ls the shell iterates through the directories specified by PATH until the executable ls is found.

The EDITOR environment variable is often used by applications that can invoke an external text editor. A user can set this variable to their preferred editor so that, for example, the crontab -e command allows the user to manipulate their crontab file with their chosen application.

The HISTFILESIZE shell variable determines the maximum number of lines saved in a user’s .bash_history file.

LS_COLORS is a highly configurable environment variable which determines how file extensions and permissions can change the way that the ls command presents file names. E.g., executable files and files ending in .sh are usually represented in a green color.

The environment variable HOME is set to the user’s home directory, defined for local users in their entry in the /etc/passwd file. The shell variable EUID is the effective UID number of the user which the shell is running as.

Leave a Comment

%d bloggers like this: