────────────────────────────────────────────
🧱 Shell script elementen
────────────────────────────────────────────
🔁 Loops
────────────────────────────────────────────
Type Voorbeeld
for : for i in *; do echo $i; done
while : while [ $count -lt 10 ]; do ...; done
until : until [ "$x" = "done" ]; do ...; done
────────────────────────────────────────────
❓ Conditionals
────────────────────────────────────────────
Type Voorbeeld
if : if [ "$x" -gt 0 ]; then echo ok; fi
case : case $var in 1) ... ;; 2) ... ;; esac
────────────────────────────────────────────
🧩 Shell parameter expansion
────────────────────────────────────────────
Vorm Beschrijving
Globbing : Wildcards (*, ?, [abc])
Brace expansion : {01..10}, {A,B,C}
────────────────────────────────────────────
➗ Vergelijkingen
────────────────────────────────────────────
Type Operatoren / Voorbeelden
Arithmetic : -eq, -ne, -lt, (( a + b ))
Strings : =, !=, -z, -n
Boolean : -a (AND), -o (OR), ! (NOT)
────────────────────────────────────────────
📦 Variabelen
────────────────────────────────────────────
Toewijzing: name="value"
Toegang: $name
Interactief: read name
────────────────────────────────────────────
🔍 Zoeken en vervangen / Reguliere expressies
────────────────────────────────────────────
Tool Gebruik
sed : Tekstvervanging (sed 's/foo/bar/')
awk : Kolomgebaseerde verwerking
grep, egrep : Zoek op basis van regex
tr : Tekens vervangen of filteren
cut : Specifieke kolommen/velden tonen
find : Bestanden zoeken (met -exec, -name, enz.)
xargs : Zet uitvoer als argument in nieuwe commando's
────────────────────────────────────────────
🔁 Streams & Redirection
────────────────────────────────────────────
Symbool Betekenis
> Overschrijf stdout naar bestand
>> Voeg stdout toe aan bestand
< Lees van bestand als stdin
<< Here document (<
& Achtergrondproces starten
&& Volgend commando alleen bij succes
`
2> Redirect stderr
&> Redirect stdout én stderr
────────────────────────────────────────────
📜 Here documents
────────────────────────────────────────────
cat <
EOF
────────────────────────────────────────────
🚪 Exit codes
────────────────────────────────────────────
Code Betekenis
0 Succes
1-255 Foutcodes (toepassingsspecifiek)
$? Toont exitcode van vorige commando
────────────────────────────────────────────
⚙️ Shell built-ins & utilities
────────────────────────────────────────────
Commando Functie
echo : Print naar stdout
read : Lees input van gebruiker
source : Laad script of env in huidige shell (. script.sh)
tee : Schrijft naar bestand én stdout
wc : Telt regels, woorden, tekens
head / tail : Toon begin of einde van bestanden
────────────────────────────────────────────
🌍 Omgevingsvariabelen
────────────────────────────────────────────
Variabele Functie
$PATH : Zoekpad voor uitvoerbare bestanden
$SHELL : Actieve shell (bijv. /bin/bash)
$? : Exitcode van laatst uitgevoerd commando
────────────────────────────────────────────
📁 Bestandspaden
────────────────────────────────────────────
Type Voorbeeld
Absoluut : /usr/local/bin/script.sh
Relatief : ./script.sh, ../backup.sh