Bash Shell Programming

Bash shell programming is still very handy. I will provide a quick summary of commands and constructs.

Assigning a Variable and Printing Out Variable

$ cat=Tom
$ echo $cat
Tom

Reading Input Into A Variable

$ read mouse
Jerry
$ echo $mouse
Jerry

Quoting Affects How Variables Get Printed

$ dog="Thomas"
$ echo "$dog"
dog
$ echo '$dog'
$dog

The IF-THEN-ELIF-THEN-ELSE Conditional

if test -f hello.txt
then
    ...
fi

Also written as:

if [ -f hello.txt ]
then
    ...
fi

For more information, look up the man page for "test"

if condition
then
    ...
elif condition
then
    ...
else
    ...
fi

The FOR Control Structure

for variable in collection
do
    ...
done
for item in 1 2 3
do
    echo $item
done

To be continued...

blogroll

social