Add lesson 7: Shell scripts

Sam Okafor 1 year ago
parent 3b3d68c47f commit 5d1cdefce56ae094c3a45cbdbc1a42cd2d19bd3b
3 changed files with 35 additions and 0 deletions
+19-0lessons/07-shell-scripts/README.md ADDED
@@ -0,0 +1,19 @@
1+# Lesson 7: Shell scripts
2+
3+This lesson covers shell scripts. You'll read a short explanation, try three small exercises and finish with a quiz.
4+
5+Full lesson: [https://glibcode.net/courses/linux-shell/lessons/7](https://glibcode.net/courses/linux-shell/lessons/7)
6+
7+## Files
8+
9+- `backup.sh`: a small script with variables and a test
10+
11+## Run it
12+
13+```sh
14+sh backup.sh
15+```
16+
17+## Exercises
18+
19+See [exercises.md](exercises.md). Ask in the forum once you've tried.
+11-0lessons/07-shell-scripts/backup.sh ADDED
@@ -0,0 +1,11 @@
1+#!/bin/sh
2+# Back up a folder with today's date in the name
3+src="$HOME/notes"
4+dest="$HOME/backups/notes-$(date +%F).tar.gz"
5+
6+if [ ! -d "$src" ]; then
7+ echo "Nothing to back up: $src is missing" >&2
8+ exit 1
9+fi
10+mkdir -p "$HOME/backups"
11+tar -czf "$dest" "$src" && echo "Saved $dest"
+5-0lessons/07-shell-scripts/exercises.md ADDED
@@ -0,0 +1,5 @@
1+# Exercises: lesson 7
2+
3+1. Look up one function or command the example uses in the official documentation. Note one option you didn't know.
4+2. Make the example ask for its input instead of using a fixed value.
5+3. Break the example on purpose: delete a bracket or misspell a name. Read the error message. Which line does it point to?