BM: Baca dalam Bahasa Melayu
World L4: Remote Kitchens
Bash scripts: variables and if
You will learn: to read and run a small script with variables, arguments and if.
Checked with Linux (Debian 13) on 1 Nov 2026
The problem
You are you in /home/you. 1 things here. Services: cron running, ssh running, nginx running.
you@kedai:~$Folder ~
- open.sh (file)
-rwxr-xr-xcan run
+ 3 hidden (ls -a)
Services
cronrunningstarts at bootsshrunningstarts at bootnginxrunningstarts at boot
The opening checklist refuses to start. It wants something from you. What?
Watch
A script: A written checklist for the shell. It runs the lines one by one. is a written checklist for the shell. Here is open.sh. Tap the line that reads what you type after ./open.sh.
Tap the line that reads your word.
0 of 1 found
Try it
A variable is a labelled jar. name=Aina fills it (no spaces around =). $name reads it. Try it.
You are you in /home/you. 1 things here. Services: cron running, ssh running, nginx running.
you@kedai:~$Folder ~
- open.sh (file)
-rwxr-xr-xcan run
+ 3 hidden (ls -a)
Services
cronrunningstarts at bootsshrunningstarts at bootnginxrunningstarts at boot
Predict
name=Aina, then echo 'Hi $name' with single quotes. What prints?
Pick one answer.
Watch
if [ -z "$worker" ] asks a yes/no question. -z means “is it empty?”. Sort the questions.
Drag a card into a box. Or tap the card, then tap the box.
Try it
Run the checklist with a name. Then make menu.txt and run it again. Watch the if change its answer.
You are you in /home/you. 1 things here. Services: cron running, ssh running, nginx running.
you@kedai:~$Folder ~
- open.sh (file)
-rwxr-xr-xcan run
+ 3 hidden (ls -a)
Services
cronrunningstarts at bootsshrunningstarts at bootnginxrunningstarts at boot
Check
Good line or needs work?
Swipe right for good, left for needs work. Or use the buttons.
name=AinaYou did it!
You can now read a script’s variables and ifs, and run it with a word.
Go deeper (optional)
Always quote jars: "$worker". Then a name with spaces stays one word. $(date +%F) fills a jar with a command’s output. shellcheck reads scripts and points at mistakes (sudo apt install shellcheck).
Real mission
chmod +x hi.sh./hi.sh Aina
0 of 3 steps done · Your ticks are saved.
Bahasa Melayu
Senarai semak pembukaan enggan bermula. Ia mahukan sesuatu daripada anda. Apa?
Skrip ialah senarai semak bertulis untuk shell. Ini open.sh. Tekan baris yang baca apa yang anda taip selepas ./open.sh.
Variable (pemboleh ubah) ialah balang berlabel. name=Aina mengisinya (tiada ruang di sekeliling =). $name membacanya. Cuba.
name=Aina, kemudian echo 'Hi $name' dengan petikan tunggal. Apa yang dicetak?
if [ -z "$worker" ] tanya soalan ya/tidak. -z bermaksud “adakah ia kosong?”. Susun soalan ini.
Jalankan senarai semak dengan satu nama. Kemudian buat menu.txt dan jalankan lagi. Tengok if tukar jawapannya.
Baris yang bagus atau perlu dibaiki?
Kini anda boleh baca pemboleh ubah dan if dalam skrip, dan jalankannya dengan satu perkataan.
You finished this before. Practice is always welcome!
Official docs: Bash manual: shell parameters · Bash manual: conditional constructs · Bash manual: conditional expressions
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?