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@kedai:~$Folder ~
- kedai/ (folder)
drwxrwxr-x - tidy.sh (file)
-rwxr-xr-xcan run
+ 3 hidden (ls -a)
Services
cronrunningstarts at bootsshrunningstarts at bootnginxrunningstarts 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@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 bootsshrunningstarts at bootnginxrunningstarts 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.
set -euo pipefailYou 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
bash -c 'set -u; echo "$NOPE"'shellcheck myscript.sh
0 of 3 steps done · Your ticks are saved.
Bahasa Melayu
Malam ini, tidy.sh berjalan. Tetapi folder kedai/tmp tak wujud. Apa jadi?
#!/bin/bash
# set -euo pipefail
cd "$HOME/kedai/tmp"
rm -f *.txt
echo "tidy done"
Ralat sebenar kata cd: … No such file or directory. Maksudnya: skrip terus berjalan dalam bilik yang salah. Ia padam menu.txt dan prices.txt, kemudian kata tidy done.
Strict mode (mod ketat) ialah penyelia yang tegas. set -euo pipefail ialah tiga peraturan. Susun apa yang setiap satu hentikan.
Kejutkan penyelia: buang # di depan baris 2 dengan sed. Kemudian jalankan tidy.sh. Fail anda mesti selamat.
Satu skrip jalankan rm -rf "$BAKUP_DIR"/*. Nama balang itu salah eja, jadi ia kosong. Tanpa -u, apa yang rm dapat?
Baris yang bagus atau perlu dibaiki?
Kini anda boleh buat skrip berhenti pada masalah pertama.
You finished this before. Practice is always welcome!
Official docs: Bash manual: the set builtin · Bash manual: pipelines
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?