A.3.More on the shell and related utilities

[Tip]Tip

You may also want to check the resources listed in SectionA.2.1, “General Linux resources” for information on the Linux CLI.

A.3.1.General information on the Bash shell

GNU Bash has an online manual.

Machtelt Garrels (mentioned in SectionA.2.1, “General Linux resources”) has a Bash Guide for Beginners.[46]

Of course, you can also check info bash.

As for books:

Albing, Carl, and JP Vossen and Cameron Newham. bash Cookbook: Solutions and Examples for bash Users. Sebastopol: O'Reilly, 2007.

Kiddle, Oliver, and Jerry Peek and Peter Stephenson. From Bash to Z Shell: Conquering the Command Line. Berkeley: Apress, 2004.

Newham, Cameron. Learning the bash Shell. 3rd ed. Sebastopol: O'Reilly, 2005.

A.3.2.Changing your shell temporarily to Bash

If your default shell (which you can check by typing echo $SHELL) is not Bash and you'd like to try using Bash, here's one way to do so:

  1. First, go to your home directory (in case you are not already there) by typing cd at the prompt.[49]

  2. Next, check to see if the .bashrc file[48] already exists by typing ls .bashrc at the prompt.[49]

  3. If .bashrc does exist, then back it up by typing mv .bashrc .bashrc.old at the prompt,[50] which will rename .bashrc to .bashrc.old.

  4. Next, type the following two lines exactly as they appear (including all of the quotation marks but without any footnote references), pressing Enter after each line, to create your own .bashrc file:

    echo 'export PS1="[bash \u@\h \W]$ "' > .bashrc[51][52][53]

    echo 'alias ls="ls --color"' >> .bashrc[53][54]

Now, to switch to Bash when you're using your default shell, just type bash at the prompt.

Compared to how my prompt looked in Section1.4, “Shells, the shell prompt, and your home directory”, it now looks like this: [bash jg18@grid ~]$

To exit Bash and return to your default, type exit at the prompt. Note that if you want to exit the terminal when you're using Bash in this way, you'll need to type exit twice: once to exit Bash and then again to exit your default shell.

A.3.3.Text processing with the shell

The best article on text processing with the shell that I know of is "Unix for Poets", and since I'm not sure whether any given link to this article (in .pdf) will last, the best way to find it is through a Google search.

A good companion to "Unix for Poets" is "egrep for Linguists".

As for books:

Dougherty, Dale, and Arnold Robbins. sed & awk. 2nd ed. Sebastopol: O'Reilly Media, 1997.

Friedl, Jeffrey. Mastering Regular Expressions. 3rd ed. Sebastopol: O'Reilly Media, 2006.

A.3.4.Shell scripting (using Bash)

[Tip]Tip

The resources mentioned in SectionA.3.1, “General information on the Bash shell” may also be helpful in learning about shell scripting.

Mendel Cooper has written an Advanced Bash-Scripting Guide.[46]

As for books:

Robbins, Arnold, and Nelson H.F. Beebe. Classic Shell Scripting. Sebastopol: O'Reilly, 2005.

A.3.5.The GNU Core Utilities (coreutils)

GNU has an online manual for coreutils.

Wikipedia has an article as well.

The blog Command Line Warriors has a post entitled Ten Cool Coreutils Commands.

You can also find a great deal of built-in information by typing info coreutils.



[48] The .bashrc file contains your personal settings for Bash. Most likely, this file does not exist.

[49] The commands cd and ls are discussed in Section3.2, “Navigating the file system”.

[50] The command mv is discussed in Section3.3, “Manipulating the file system”.

[51] This will set up your Bash prompt to look like the one shown in Section1.4, “Shells, the shell prompt, and your home directory” but with the word bash after the [ character to remind you that you're using Bash.

[52] Note that there is a space after the $ character.

[53] The command echo and the I/O redirection operators > and >> are discussed in Section3.5, “Working with text streams”.

[54] This line is optional but recommended, as it will add color to the output of ls,[49] so that when you get the listing of a directory's contents with ls, different types of files (including directories, executables, etc.) will appear in different colors, which makes it easier to tell them apart.

However, as far as I know, this line will only work when your terminal supports color (which it probably does), which you can check by typing echo $TERM and confirming that the following is the output:

xterm-color

Finally, this line was taken from a discussion on a Brandeis University bulletin board in a thread called "SSH Colors".


Back to Guide main page