.
  • Print
AdvancedComputing / The BASH Shell

The Bash Shell

I have used a number of Unix/Linux shells over the years, but my shell of preference is the bash shell. My favorite guide to the bash shell is the Advanced Bash-Scripting Guide. This page contains snippets of bash trivia that I've found useful and don't want to forget.

For general Linux/Unix information (i.e., not specific to the bash shell), see Using Linux.

On this page:

The Prompt

Within your .bashrc, the shell prompt is controlled using the declare -x PS1="prompt" , where prompt is what you want as your main prompt. There are three other prompt variables (PS2, PS3, PS4) controlling specific use prompts.

There are several special character sequences defined to include dynamic information or special characters into your prompt. These are:

\tthe time  \dthe date
\nCRLF  \sthe name of the shell
\wthe current working directory  \Wthe last element of PWD
\uyour username  \hthe hostname
\#the command number of this command  \!the history number of this command
\O the character code in octal O  \\a backslash

Found this info at www.informatik.uni-frankfurt.de/doc/texi/bash_4.html.

For example, I have:

        declare -x PS1="[\d \t \!] "

and my prompt looks like:

        [Sat Aug 19 18:39:37 501] 

(with a space at the end).

awc 2006-08-19 18:34:33

Bash startup files

My startup files are somewhat complicated, because I use a system that is setup for multiple users that I developed for work. There are two global files (which in each $HOME directory are links to the sytem-wide files) and two which are for the individual users to customize. This way I can push global changes out to everyone, but savvy individual users can override my settings or simply add their own customizations. The set of four files are:

    .bashrc              global stuff only needed for interactive shells
    .bashrc-ni           global stuff needed for both interactive and non-interactive shells
    .bashrc-private      personal stuff only needed for interactive shells
    .bashrc-ni-private   personal stuff needed for both interactive and non-interactive shells
awc 2007-04-17 12:13:59

Tips

To grep for a TAB character (or use a TAB in any command), when you want the TAB character, type Ctrl-V and then TAB.

awc 2008-01-22 10:27:52


Change is the law of life. And those who look only to the past or present are certain to miss the future.

John F. Kennedy

Look for:
A2 Web Hosting
Creative Commons License
loaded 2010-09-09 17:24:25 • last modified 2008-01-22 10:27:52
Privacy PolicyDisclaimer
• awcfamily.com is powered by PmWiki v.2001944 •
• all content (unless noted otherwise) © 2010 A W Colley
this website and its contents are licensed under the
Creative Commons Attribution-NonCommercial-NoDerivs 2.5 License
Registrar
Valid XHTML 1.0 Transitional