bash command shell

A rich command line interface invoked by      bash

Bash stands for Bourne Again SHell which is a pun on "born-again-Christians".

bash basics

Basics are covered here.

bash redirection

uses the operators







std-output 1 and std-error-output 2

(1) simplest use case

ls > dirlist.txt

is an abbreviation because 1 > can be shortened to >

Similarly 0 < can be shortened, omitting the 0 standing for the std-input filedescriptor /dev/fd/0 .

(2) full feature use

ls 1 > dirlist.txt 2 > errlist.txt

The ls command produces 2 separate streams thereby easing the parsing of formatted standard output uninterrupted by error messages breaking the format. Omitting the 2 > business will make you see any err msg on the screen, i.e. unredirected away from the console device. Keep in mind that both streams are always produced by ls but they may be empty, as in the case of no error occurring at all.

(3) cryptic use

If you think that typing out (2) is too tedious, you can shorten it to

ls 1 > dirlist.txt 2>&1

doing the exact same thing. It means: "put the error stream 2 to the same place as stream 1, which is the dirlist file on the hard drive". But other than saving a few keystrokes this use of syntax achieves nothing. It makes your scripts harder to read, though, which is "un- Ubuntu ish".

The 1 > 2 > business applies to many commands in /bin and /usr/bin , such as "/usr/bin/find" but not all (e.g. "/usr/bin/passwd" does not work this way).

file descriptors /dev/fd/1 i.e. "std output"

/dev/fd/0 is standard input, i.e. normally the keyboard typing.

using examples

let us make use of redirection:

wall <<< HelloThisIsAwallTest

saves you the bother of creating a text file as input for wall ( = write to all).

GNU provides further examples but unlike Ubuntu they start with the cryptic ones and hardly ever give a simple plain example.

Practising redirection is quick to do using mc.

See Also

Ubuntu references on bash:

External Links

GNU offers a manual, but their style of explaining is somewhat cryptic and lacks examples - unlike Ubuntu .


bash (last edited 2015-02-23 23:13:03 by mail77)