Pages

Wednesday, June 1, 2011

Important Bash Shell Variables


These variables are most often inherited or declared when a shell is started. A great reference for bash shell variable, bash builtin commands, and bash in general is SSC (2000).
  • HOME - home directory, abbreviated as ~
  • MAIL - name of file that mail is stored in (mailbox)
  • MAILCHECK - sets the frequency at which bash checks for mail
  • PATH - directory paths to search for executable files. According to A Practical Guide to Linux, p.329, the PATH is set in /etc/profile. On my Linux box, /etc/profile adds /usr/X11R6/bin to the path, which means that the path must be set before by another configuration file. The .bash_profile file in my home directory adds /home/ambler/bin to the path. On my Linux box, the first command to set the path would seem to be in /etc/rc.d/rc.sysinit, which is one of the shell scripts invoked by the init process (inittab). Then, /etc/profile adds /usr/X11R6/bin. Finally, .bash_profile adds /home/ambler/bin.
  • PS1 - prompt string. Things that can be put in the prompt string include \h (hostname), \u (username), \w (absolute pathname of working directory), \W (name of working directory w/o path), \d (date), \t (time). See p.331 of A Practical Guide to Linux for more details. On my Red Hat boxes, the primary prompt string is set in the /etc/bashrc file. The prompt is also set in /etc/profile, but the setting in bashrc seems to take precedence. I also have a .bashrc file, which in turn runs /etc/bashrc, which sets the prompt. This means that the same prompt is used by xterm and rxvt in X sessions. On my Slackware box, the command line prompt is set in /etc/profile. The xterm and rxvt prompts are different, since I don't have a .bash_profile file which is run when an xterm is started. In fact, I don't know where the prompt is set in X sessions. It is not set by /usr/X11R6/lib/X11/app-defaults/XTerm.
  • PS2 - secondary prompt string.

No comments:

Post a Comment