World map

 

BM: Baca dalam Bahasa Melayu

World L4: Remote Kitchens

Safer scripts: set -euo pipefail

You will learn: to make a script stop at the first problem, before it does damage.

Checked with Linux (Debian 13) on 1 Nov 2026

The problem

Tonight, tidy.sh runs. But the folder kedai/tmp does not exist. What happens?

#!/bin/bash
# set -euo pipefail
cd "$HOME/kedai/tmp"
rm -f *.txt
echo "tidy done"

Pick one answer.

Watch

You are you in /home/you. 2 things here. Services: cron running, ssh running, nginx running.

You are hereyou@kedai:~$

Folder ~

  • kedai/ (folder)drwxrwxr-x
  • tidy.sh (file)-rwxr-xr-xcan run

+ 3 hidden (ls -a)

Services

  • cronrunningstarts at boot
  • sshrunningstarts at boot
  • nginxrunningstarts at boot

The real error says cd: … No such file or directory. Plain words: the script kept going in the wrong room. It deleted menu.txt and prices.txt, then said tidy done.

Watch

Strict mode is a strict supervisor. set -euo pipefail is three rules. Sort what each one stops.

Drag a card into a box. Or tap the card, then tap the box.

        Try it

        Wake the supervisor: remove the # in front of line 2 with sed. Then run tidy.sh. Your files must survive.

        You are you in /home/you. 4 things here. Services: cron running, ssh running, nginx running.

        You are hereyou@kedai:~$

        Folder ~

        • kedai/ (folder)drwxrwxr-x
        • menu.txt (file)-rw-r--r--
        • prices.txt (file)-rw-r--r--
        • tidy.sh (file)-rwxr-xr-xcan run

        + 3 hidden (ls -a)

        Services

        • cronrunningstarts at boot
        • sshrunningstarts at boot
        • nginxrunningstarts at boot

        Predict

        A script runs rm -rf "$BAKUP_DIR"/*. The jar name has a typo, so it is empty. Without -u, what does rm get?

        Pick one answer.

        Check

        Good line or needs work?

        Swipe right for good, left for needs work. Or use the buttons.

        1 / 4set -euo pipefail
        set -euo pipefail

        You did it!

        You can now make a script stop at the first problem.

        Go deeper (optional)

        -e has blind spots: it ignores a failure inside an if test, or before && and ||. To allow one failure on purpose, write cmd || true. trap can tidy up when a script stops. Test scripts on a throwaway machine first.

        Real mission

        1. bash -c 'set -u; echo "$NOPE"'
        2. shellcheck myscript.sh

        0 of 3 steps done · Your ticks are saved.