Skip to content
Hands-on IT IT Drills

Day 0: The Training Ground

Goal: Create the lab VM, install Docker and the tools, fetch the companion code, start notes and prepare the toolbox. · Duration: approx. 45 min · Prerequisite: none

Briefing

  • You work in the Ubuntu 26.04 VM sh, as user ubuntu in ~/sh-lab.
  • notes is the application your scripts look after: notes-api (Go) stores notes in Postgres, nginx sits in front of it and writes every request to an access log.
  • Your toolbox lives in ~/sh-lab/werkzeug: bin/ for scripts, lib/ for shared functions, tests/ for tests. env.sh puts bin/ at the front of PATH.
  • Tools: ShellCheck finds bugs in scripts, shfmt formats them, bats tests them, jq reads JSON.
 you ─ssh─► VM sh:  curl 127.0.0.1:8080 ─► nginx ─► notes-api ─► Postgres
                                          └─► ~/sh-lab/notes/logs/access.log
                    ~/sh-lab/werkzeug/{bin,lib,tests}

Drill 1: The lab VM

On the laptop (Multipass from multipass.run):

multipass launch 26.04 --name sh --cpus 2 --memory 4G --disk 20G
multipass exec sh -- bash -c "echo '$(cat ~/.ssh/id_ed25519.pub)' \
  >> ~/.ssh/authorized_keys"
multipass info sh | grep IPv4
ssh ubuntu@<IP from the output>

From here on, everything runs in the VM:

bash --version | head -1
echo "$SHELL"
readlink -f /bin/sh

Expected:

GNU bash, version 5.3.9(1)-release (x86_64-pc-linux-gnu)
/bin/bash
/usr/bin/dash

Your login shell is Bash. On Ubuntu, however, /bin/sh is dash, a small, strictly POSIX-compliant shell. So a script that starts with #!/bin/sh does not run in Bash – more on that on Day 1. On a Mac with Apple Silicon, you see aarch64 instead of x86_64.

Save your progress? Sign up for free

Drill 2: Docker and tools

sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
  -o /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \
https://download.docker.com/linux/ubuntu $(. /etc/os-release; echo $VERSION_CODENAME) \
stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
sudo apt-get update -qq
sudo apt-get install -y -qq docker-ce docker-ce-cli containerd.io \
  docker-compose-plugin jq git xz-utils >/dev/null
sudo usermod -aG docker ubuntu

ShellCheck and shfmt come as single binaries from GitHub, bats via git:

case "$(uname -m)" in
  x86_64)  SC=x86_64;  SF=amd64 ;;
  aarch64) SC=aarch64; SF=arm64 ;;
esac
cd /tmp
U=https://github.com/koalaman/shellcheck/releases/download/v0.11.0
curl -fsSL $U/shellcheck-v0.11.0.linux.$SC.tar.xz | tar -xJ
sudo install -m 0755 shellcheck-v0.11.0/shellcheck /usr/local/bin/
sudo curl -fsSL -o /usr/local/bin/shfmt \
  https://github.com/mvdan/sh/releases/download/v3.14.1/shfmt_v3.14.1_linux_$SF
sudo chmod 0755 /usr/local/bin/shfmt
git clone -q --depth 1 --branch v1.14.0 https://github.com/bats-core/bats-core.git \
  /tmp/bats 2>/dev/null
sudo /tmp/bats/install.sh /usr/local >/dev/null

Log out (exit) and back in so that the docker group takes effect:

docker --version
docker compose version
shellcheck --version | sed -n 2p
shfmt --version
bats --version
jq --version

Expected:

Docker version 29.9.2, build a82e528
Docker Compose version v5.6.1
version: 0.11.0
v3.14.1
Bats 1.14.0
jq-1.8.1

The case above is already a piece of shell script: depending on the processor, it picks the matching file name. On Day 3, you write branches like this yourself.

Save your progress? Sign up for free

Drill 3: Companion code and environment

mkdir -p ~/sh-lab/setup
git clone -q https://github.com/thomaszachmann/shell-scripting-zum-anfassen.git \
  ~/sh-lab/code
cp ~/sh-lab/code/setup/env.sh ~/sh-lab/setup/
cat ~/sh-lab/setup/env.sh
source ~/sh-lab/setup/env.sh
echo "$PATH" | cut -d: -f1

Expected:

# setup/env.sh – zu Beginn jedes Trainingstags einlesen: source ~/sh-lab/setup/env.sh
export LAB="$HOME/sh-lab"
export NOTES_URL="http://127.0.0.1:8080"           # notes hinter nginx
export NOTES_API_KEY="lab-api-key-123"             # nur Labor
export NOTES_LOG="$LAB/notes/logs/access.log"      # Zugriffslog von nginx
case ":$PATH:" in
  *":$LAB/werkzeug/bin:"*) ;;
  *) export PATH="$LAB/werkzeug/bin:$PATH" ;;       # eigene Skripte zuerst
esac
true
/home/ubuntu/sh-lab/werkzeug/bin

source runs the file in your current shell – the variables stay set afterwards. A normal call (bash env.sh) would run in a new shell, and everything would be gone again afterwards. The case makes sure that bin/ does not end up in PATH once more with every source.

Save your progress? Sign up for free

Drill 4: Start notes

cd ~/sh-lab/code/notes/notes-api
docker build -q --build-arg VERSION=0.4.0 -t notes-api:0.4.0 . | cut -c1-19
cp -R ~/sh-lab/code/notes-stack ~/sh-lab/notes && cd ~/sh-lab/notes
docker compose up -d --wait 2>&1 | grep -E 'Healthy|Started' | tail -2
curl -s $NOTES_URL/healthz; echo
curl -s -X POST -H "X-API-Key: $NOTES_API_KEY" \
  -H 'Content-Type: application/json' -d '{"text":"erste Notiz"}' $NOTES_URL/notes
echo
tail -2 "$NOTES_LOG"

Expected (shortened, a few minutes the first time):

sha256:f453f6401d46
 Container notes-db-1 Healthy
 Container notes-notes-api-1 Healthy
ok
{"id":"…","text":"erste Notiz"}
172.19.0.1 [02/Nov/2026:11:56:21 +0000] "GET /healthz HTTP/1.1" 200 3 0.002 curl/8.18.0
172.19.0.1 [02/Nov/2026:11:56:21 +0000] "POST /notes HTTP/1.1" 201 67 0.009 curl/8.18.0

Each line in the log is one request: sender, time, request, status, bytes, duration in seconds and program. From Day 6 on, you analyze exactly these lines.

Warning: On Ubuntu 26.04, the AppArmor profile docker-default blocks the Postgres container. That is why compose.yaml contains the line apparmor=unconfined for db – in the lab only.

Save your progress? Sign up for free

Drill 5: The toolbox

mkdir -p ~/sh-lab/werkzeug/{bin,lib,tests}
ls ~/sh-lab/werkzeug
type -a ls cd

Expected:

bin
lib
tests
ls is aliased to `ls --color=auto'
ls is /usr/bin/ls
ls is /bin/ls
cd is a shell builtin
  • {bin,lib,tests} is brace expansion: Bash turns it into three words before mkdir starts.
  • type -a shows what is behind a name: an alias, a program in PATH, or a builtin that the shell runs itself. ls shows up twice because on Ubuntu /bin is just a link to /usr/bin. Only your interactive shell knows the alias; in a script, it is missing. cd has to be a builtin – a separate program could not change your shell’s directory.

Save your progress? Sign up for free

Checkpoint

docker compose -f ~/sh-lab/notes/compose.yaml ps --format '{{.Service}}' | sort

Expected: three running services (migrate has finished and exited).

db
notes-api
proxy
curl -s -o /dev/null -w '%{http_code}\n' $NOTES_URL/notes

Expected:

200
command -v shellcheck shfmt bats jq

Expected:

/usr/local/bin/shellcheck
/usr/local/bin/shfmt
/usr/local/bin/bats
/usr/bin/jq

Challenge

Find all commands whose name consists only of lowercase letters and ends in sh – that is, shells like bash, dash and sh.

Note: compgen -c lists all commands the shell knows.

Solution

compgen -c | grep -E '^[a-z]*sh$' | sort -u

Expected (depending on the installed packages):

bash
capsh
chsh
dash
hash
instmodsh
podmansh
rbash
sh
ssh
tclsh

rbash is a restricted Bash, hash is a builtin, ssh and chsh are not shells at all. That is part of the lesson too: a pattern finds what matches, not what you meant.

Save your progress? Sign up for free

Enterprise Note

  • One toolbox, many servers: Scripts belong in a Git repository and are distributed from there, not maintained on each server individually (Day 14).
  • Pinned versions: ShellCheck, shfmt and bats run in CI with the same versions as locally – otherwise CI reports errors that nobody sees locally.
  • Bash is not everywhere: Alpine containers and BusyBox only have sh. If you need scripts there, write them POSIX-compliant or install bash explicitly.