Diverses

Command Erfolg

Wenn ein Command im if Statement evaluiert wird, wird es true, wenn der Command erfolgreich war

if <command>;
then
    echo "Success"
fi

Informationen zu Commands

command -V <command> # Mehr Information, wo <command> herkommt
command -V cd # cd is a shell built in

which <command> # Wie oben, nur etwas rudimentärer
which mv # /bin/mv

man <command> # Öffnet die Manual Page für Commands

Kalkulation mit bc

bc <<< "scale=10; 5*5"
bc ist der Built-in Calculator und hat standardmäßig nur eine Nachkommastelle Präzision (scale)

Verzögerte Exekution

sleep <sec>
Wartet <sec> Sekunden... wer hätt's gedacht

wait <pid>
Wartet bis der Prozess <pid> fertig ist

Argumente mit getopts

while wird oft mit einem case statement für getopts verwendet, um gegebene Argumente zu bestimmen

Beispiel:

while getopts ab:c:de:f:gh: option
do
    case "${option}"
    in
        a) avar="true";;
        b) bvar=${OPTARG};;
        c) cvar=${OPTARG};;
        d) dvar=$OPTARG;;
        e) evar=$OPTARG;;
        f) fvar="true";;
        g) gvar=$OPTARG;;
        \?) usage
            exit 1;;
    esac
done

Options die ein :-postfix haben, nehmen ein Argument durch $OPTARG an \? ist für unbekannte Argumente und usage gibt ein "Tutorial"