Computing / The BASH Shell

U N D E R   C O N S T R U C T I O N

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.

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

(I found this info at www.informatik.uni-frankfurt.de/doc/texi/bash_4.html, but that page no longer exists.)

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).


  1. 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.
  2. To convert lower case (on stdin) to upper (on stdout): tr a-z A-Z

Read a file (or command output) into a array, with each line as a single array element

The following reads the contents of MAKE_KML.TMP into a new array RAWDATA, one line per array element, and then reads the output of the grep command (sorted and then throwing out redundant lines) into RAWDATA2, one line of output per array element:

RAWDATA2=( $(grep SLAT *.buf | sort | uniq) )

The first two lines set newline as the field separator. You may want to set it back to space after reading the file into the array.

IFS=' '

The key to this whole business is sincerity. Once you can fake that, you’ve got it made.

Monte Clark

A2 Web Hosting
Creative Commons License
Get your Domain at GoDaddy.com
search engine by freefind advanced

loaded 2024-06-14 15:03:44 • last modified 2013-10-26 01:39:42
Privacy PolicyDisclaimer
• awcolley.com is powered by PmWiki
• all content (unless otherwise noted) © 2024 A W Colley