Bash - Overview

Bash is (almost) universally available on Linux, macOS, and even Windows

Cowsay

$ brew install cowsay
$ cowsay hello
 _______
< hello >
 -------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Fortune

$ fortune
QOTD:
	"If you keep an open mind people will throw a lot of garbage in it."
$ fortune
QOTD:
	"You're so dumb you don't even have wisdom teeth."
$ fortune | cowsay
 _______________________________________
/ The opulence of the front office door \
| varies inversely with the fundamental |
\ solvency of the firm.                 /
 ---------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
$ fortune | cowsay -f tux
 ______________________________________
/ You k'n hide de fier, but w'at you   \
| gwine do wid de smoke?               |
|                                      |
| -- Joel Chandler Harris, proverbs of |
\ Uncle Remus                          /
 --------------------------------------
   \
    \
        .--.
       |o_o |
       |:_/ |
      //   \ \
     (|     | )
    /'\_   _/`\
    \___)=(___/
$ cowsay -l
Cow files in /usr/local/Cellar/cowsay/3.03/share/cows:
beavis.zen bong bud-frogs bunny cheese cower daemon default dragon
dragon-and-cow elephant elephant-in-snake eyes flaming-sheep ghostbusters
head-in hellokitty kiss kitty koala kosh luke-koala meow milk moofasa moose
mutilated ren satanic sheep skeleton small sodomized stegosaurus stimpy
supermilker surgery telebears three-eyes turkey turtle tux udder vader
vader-koala www

Bash Script

bash syntax: https://devmanual.gentoo.org/tools-reference/bash/index.html

Evaluate numbers

$((i-1))

Check if exists

if [ -d foo ]; then
    mkdir foo
fi

Loop

for S in FOO BAR BAZ
do
    ...
done

Skeleton of a bash script

#!/bin/bash

usage="Usage: server.sh (start|stop)"

# command is 'start' or 'stop'
command=$1

case $command in

    (start)

        ...

        ;;

    (stop)

        ...

        ;;

    (*)

        echo $usage
        exit 1
        ;;
esac