if-elif-else-fi loop

Untitled

#!/bin/bash

if [ $# -gt 2 ]; then
    echo "More than 2 arguments";
elif [ $# -gt 1 ]; then
    echo "More than 1 argument";
elif [ $# -gt 0 ]; then
    echo "Not enough arguments";
else
    echo "Arguments required";
fi;

case statement options

Untitled

#!/bin/bash

echo "What is your favourite image processor?";
read pname;

case $pname in
    [gG]imp | inkscape)
        echo "Good choice";
        ;;
    [aA]dobe*)
        echo "Absolutely proprietary and costs a lot";
        ;;
    imagej)
        echo "Measuring things on the image?";
        ;;
    *)
        echo "$pname is a new find for me";
        ;;
esac;

C-style for loop → one variable

Untitled

#!/bin/bash

begin=1;
finish=10;

for (( a = $begin; a < $finish; a++ )); do
    b=$(( a**2 ));
    echo $b;
done;

C-style for loop → two variables

Untitled