This is a very short and incom­plete intro­duc­tion to the Bourne-Again Shell.

On the com­man­d­line most pro­grams fol­low the sim­ple prin­ci­ple of cre­at­ing and mod­i­fy­ing plain text. To make this approach extremly pro­duc­tive the Bash offers some mechanisms.

The so-called pipe char­ac­ter (|) acts like a plug to send the out­put of one pro­gram to the input of another. This way way you can eas­ily plug together tool­chains, e.g.

`ls | rev` 

com­bines the list and revert com­mand.
To direct the out­put of a pro­gram into a file, instead of another pro­gram, you can use the > character.

ls *.* > somefile.txt

A sin­gle > writes a new file, while a dou­ble >> appends to a file (if it exists).

Vari­ables are another fea­ture. The value of a vari­able may be accessed after defin­ing through putting a $ in front of your vari­able name:

HELLO="Hello World"
echo $HELLO

With back­ticks you can cap­sule the out­put of a pro­gram, this means the result of the com­mand inside the back­ticks will gen­er­ate com­mand line text. For exam­ple: if ls *.* | head -1 = some.txt, then

cat `ls *.* | head -1` 

is the same as

cat some.txt 

This is espe­cially use­ful to define variables.

FILE=`ls *.* | head -1`


Since the Bash is not only a user inter­face, but a fairly pow­er­ful pro­gram­ming lan­guage, it offers loops, one of the most basic and pow­er­ful prin­ci­ples of com­puter programming.

for–loops can be exe­cuted on a space sep­a­rated list of ‘words’. The loop-definition may be saved in a file or entered directly on the com­man­d­line: for LETTER in A B; do echo $LETTER ;done
A for–loop may of course be com­bined with a com­mand cap­suled in backticks.

for FILE in `ls *.*`; do echo $FILE; done

A while–loop runs while a cer­tain pre­con­di­tion is true:

while [ 1 -lt 2 ]
     echo "true"

-lt means less than.

Also avail­able:
-eq = equal
-le = less equal
-gt = greater than
-ge = greater equal

This loop will basi­cally run for­ever, since 1 will always be less than 2.
Com­bined with a vari­able and upcount­ing inside backticks,

while [ $COUNT -le 10 ]
    echo $COUNT
    COUNT=`expr $COUNT + 1`

the loop will stop.

You find a good intro­duc­tion at floss man­u­als. For a com­plete intro­duc­tion check the Advanced Bash Script­ing Guide.
For inspi­ra­tion read $(echo echo) echo $(echo): Com­mand Line Poetics