BM: Baca dalam Bahasa Melayu
World L4: Remote Kitchens
Loops and exit codes
You will learn: to repeat steps with a for loop, and to read a program's exit code.
Checked with Linux (Debian 13) on 1 Nov 2026
The problem
You are you in /home/you. 2 things here. Services: cron running, ssh running, nginx running.
you@kedai:~$Folder ~
- check.sh (file)
-rwxr-xr-xcan run - menu/ (folder)
drwxrwxr-xnasi-lemak.txt roti-canai.txt
+ 3 hidden (ls -a)
Services
cronrunningstarts at bootsshrunningstarts at bootnginxrunningstarts at boot
The dish checker says one dish is missing. Then echo $? prints 1. What does that 1 mean?
Watch
A loop: Do the same steps for each item: for dish in a b c; do ...; done. repeats steps for each item. Here is check.sh. Tap the line that starts the loop.
Tap the start of the loop.
0 of 1 found
Try it
Type a loop of your own, all on one line.
You are you in /home/you. 2 things here. Services: cron running, ssh running, nginx running.
you@kedai:~$Folder ~
- check.sh (file)
-rwxr-xr-xcan run - menu/ (folder)
drwxrwxr-xnasi-lemak.txt roti-canai.txt
+ 3 hidden (ls -a)
Services
cronrunningstarts at bootsshrunningstarts at bootnginxrunningstarts at boot
Watch
Every program ends with an exit code: a thumbs-up (0) or a number for trouble. $? shows the last one. Sort them.
Drag a card into a box. Or tap the card, then tap the box.
Predict
One dish is still missing. You run ./check.sh && echo "Open the shop". What happens?
Pick one answer.
Try it
Add the missing dish, then run the checker again. It should end with 0.
You are you in /home/you. 2 things here. Services: cron running, ssh running, nginx running.
you@kedai:~$Folder ~
- check.sh (file)
-rwxr-xr-xcan run - menu/ (folder)
drwxrwxr-xnasi-lemak.txt roti-canai.txt
+ 3 hidden (ls -a)
Services
cronrunningstarts at bootsshrunningstarts at bootnginxrunningstarts at boot
Check
Build: run the checker, and only if it fails, say “Not yet”.
Tap the pieces in the right order.
You did it!
You can now loop over items and read exit codes.
Go deeper (optional)
while [ … ]; do … done loops while a question says yes. systemd reads your exit code too. A timer’s service shows failed when its script ends with non-zero. So end scripts with a meaningful number.
Real mission
for f in *.txt; do wc -l "$f"; donels nope; echo $?
0 of 2 steps done · Your ticks are saved.
Bahasa Melayu
Penyemak hidangan kata satu hidangan tiada. Kemudian echo $? cetak 1. Apa maksud 1 itu?
Gelung ulang langkah untuk setiap item. Ini check.sh. Tekan baris yang memulakan gelung.
Taip gelung anda sendiri, semuanya dalam satu baris.
Setiap program tamat dengan exit code (kod keluar): tanda bagus (0) atau nombor untuk masalah. $? tunjuk yang terakhir. Susun mereka.
Satu hidangan masih tiada. Anda jalankan ./check.sh && echo "Open the shop". Apa jadi?
Tambah hidangan yang tiada, kemudian jalankan penyemak lagi. Ia patut tamat dengan 0.
Bina: jalankan penyemak, dan hanya jika ia gagal, sebut “Not yet”.
Kini anda boleh buat gelung untuk setiap item dan baca kod keluar.
You finished this before. Practice is always welcome!
Official docs: Bash manual: looping constructs · Bash manual: exit status · Bash manual: lists (&& and ||)
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?