BM: Baca dalam Bahasa Melayu
World L2: Keys & Staff
Environment variables and PATH
You will learn: to set notes that programs can read, and to teach the shell where your tools live.
Checked with Linux (Debian 13) on 1 Nov 2026
The problem
You keep a helper script called menu in ~/tools. You type menu. The shell says -bash: menu: command not found. It is right there! Why?
Pick one answer.
Watch
You are you in /home/you. 1 things here. Services: cron running, ssh running, nginx running.
you@kedai:~$Folder ~
- tools/ (folder)
drwxrwxr-xmenu
+ 3 hidden (ls -a)
Services
cronrunningstarts at bootsshrunningstarts at bootnginxrunningstarts at boot
Notes on the wall: environment variables. $HOME is your room. $PATH lists the rooms the shell searches for commands, split by :.
Predict
You type SHOP=Kancil, then run tools/menu. It prints Today at : nasi lemak. Why is SHOP empty?
Pick one answer.
Try it
Pin the note on the wall: export SHOP=Kancil. Then run tools/menu again.
You are you in /home/you. 1 things here. Services: cron running, ssh running, nginx running.
you@kedai:~$Folder ~
- tools/ (folder)
drwxrwxr-xmenu
+ 3 hidden (ls -a)
Services
cronrunningstarts at bootsshrunningstarts at bootnginxrunningstarts at boot
Hint
No spaces around=.Check
Say PATH is /home/you/tools:/usr/local/bin:/usr/bin:/bin. You type menu. Put the rooms in the order the shell searches.
Searched first at the top. Put these in order. Use the arrows, or drag.
- /home/you/tools
- /usr/local/bin
- /bin
- /usr/bin
Try it
Put ~/tools at the front of the PATH: The list of folders the shell searches, in order, when you type a command name.: export PATH="$HOME/tools:$PATH". Then type just menu.
You are you in /home/you. 1 things here. Services: cron running, ssh running, nginx running.
you@kedai:~$Folder ~
- tools/ (folder)
drwxrwxr-xmenu
+ 3 hidden (ls -a)
Services
cronrunningstarts at bootsshrunningstarts at bootnginxrunningstarts at boot
Hint
$PATH at the end keeps the old list.Check
Good PATH habit, or risky?
Swipe right for good, left for needs work. Or use the buttons.
export PATH="$HOME/tools:$PATH"You did it!
You can now share notes with export and tell the shell where tools live.
Go deeper (optional)
These changes last until you log out. To keep them, add the export line to ~/.profile. On Debian, ~/.profile already adds ~/bin to PATH when it exists. env lists every exported note; unset SHOP takes one down.
Real rep (optional): on Linux, echo $PATH, then which ls, then env | wc -l.
Bahasa Melayu
Anda simpan skrip pembantu bernama menu dalam ~/tools. Anda taip menu. Shell kata -bash: menu: command not found. Ia ada di situ! Kenapa?
Nota di dinding: environment variables (pemboleh ubah persekitaran). $HOME ialah bilik anda. $PATH senaraikan bilik yang shell cari untuk arahan, dipisah dengan :.
Anda taip SHOP=Kancil, kemudian jalankan tools/menu. Ia cetak Today at : nasi lemak. Kenapa SHOP kosong?
Lekatkan nota di dinding: export SHOP=Kancil. Kemudian jalankan tools/menu sekali lagi.
=.Katakan PATH ialah /home/you/tools:/usr/local/bin:/usr/bin:/bin. Anda taip menu. Susun bilik ikut urutan shell mencari.
Letak ~/tools di depan PATH: export PATH="$HOME/tools:$PATH". Kemudian taip menu sahaja.
$PATH di hujung kekalkan senarai lama.Tabiat PATH yang baik, atau berisiko?
Kini anda boleh kongsi nota dengan export dan beritahu shell di mana alat berada.
You finished this before. Practice is always welcome!
Official docs: Bash manual: Bash Variables · Bash manual: Environment · environ(7): the environment · which (Debian 13 man page)
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?