Skip to content

Commit 3f39be4

Browse files
committed
docs(linux): add bash scripting fundamentals - class notes + 20 exercises
1 parent 848c1b2 commit 3f39be4

3 files changed

Lines changed: 668 additions & 1 deletion

File tree

02-linux/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Hands-on from day one - setting up a real Linux server environment and learning
1717
- [x] Write a bash for loop for bulk file operations
1818
- [ ] Users, groups, and permission models
1919
- [ ] Process management and system monitoring
20-
- [ ] Shell scripting fundamentals
20+
- [x] Shell scripting fundamentals
2121

2222
## Contents
2323

@@ -44,6 +44,7 @@ Hands-on from day one - setting up a real Linux server environment and learning
4444
- [Shared Server Scenario Lab](exercises/shared-server-scenario-lab.md) - Full server setup: users, groups, permissions, log analysis, admin access, debugging (Bonus Lab)
4545
- [systemd Node.js Service Lab](exercises/systemd-node-service-lab.md) - Process vs service, unit file structure, self-healing, boot flow, troubleshooting
4646
- [Immortal Bash Service Lab](exercises/immortal-service-lab.md) - Bash script as systemd service, chmod +x, pgrep -f, file ownership trap
47+
- [Bash Scripting Fundamentals](exercises/bash-scripting-fundamentals.md) - Scripting intro, variables, input, conditions, 20 exercises (Homework)
4748

4849
### Journal
4950
- [Week 02 Notes](journal/week-02-notes.md) - Setup reflections, CLI discoveries, DevOps connections

02-linux/commands/core-commands.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,79 @@ Commands learned during the Linux module, organized by category.
196196
| `usermod -aG <group> <user>` | Add user to group (append, keeps existing groups) | `sudo usermod -aG devteam dev1` |
197197
| `cut -d<delim> -f<field>` | Extract fields from structured text | `cut -d: -f1 /etc/passwd` |
198198

199+
## Bash Scripting
200+
201+
| Command / Syntax | What It Does | Example |
202+
|-----------------|-------------|---------|
203+
| `#!/bin/bash` | Shebang - declares the interpreter | Must be line 1 of every script |
204+
| `chmod +x script.sh` | Grant execute permission to a script | `chmod +x hello.sh` |
205+
| `echo` | Print text or variables to stdout | `echo "Hello, $NAME"` |
206+
| `read VAR` | Read user input into variable | `read NAME` |
207+
| `read -p "prompt" VAR` | Read with inline prompt (no newline) | `read -p "Enter name: " NAME` |
208+
| `read -s VAR` | Read silently (no echo - for passwords) | `read -s PASSWORD` |
209+
| `NAME="value"` | Variable assignment (no spaces around `=`) | `NAME="david"` |
210+
| `$NAME` | Variable reference | `echo $NAME` |
211+
| `$(command)` | Command substitution - capture output | `DATE=$(date +"%Y-%m-%d")` |
212+
| `$(( expr ))` | Arithmetic expression | `RESULT=$(( 5 + 3 ))` |
213+
| `$0` | Script name (special variable) | `echo "Script: $0"` |
214+
| `$?` | Exit code of last command | `echo "Exit: $?"` |
215+
216+
## System Info
217+
218+
| Command | What It Does | Example |
219+
|---------|-------------|---------|
220+
| `whoami` | Print current username | `whoami``david` |
221+
| `hostname` | Print system hostname | `hostname``ubuntu-lab` |
222+
| `date` | Print current date and time | `date` |
223+
| `date +"%Y-%m-%d"` | Format date for filenames | `DATE=$(date +"%Y-%m-%d")` |
224+
| `df -h` | Disk usage by filesystem (human-readable) | `df -h /` |
225+
| `du -sh path` | Size of a file or directory | `du -sh notes.txt``4.0K` |
226+
227+
## Text Processing (Extended)
228+
229+
| Command | What It Does | Example |
230+
|---------|-------------|---------|
231+
| `rev` | Reverse each line character by character | `echo "devops" \| rev``spoved` |
232+
| `sed -i 's/old/new/g'` | In-place substitution in file (global) | `sed -i 's/error/warning/g' app.log` |
233+
| `wc -w` | Count words in input | `wc -w < notes.txt` |
234+
| `wc -l` | Count lines in input | `ls \| wc -l` |
235+
| `cut -f1` | Extract first tab-delimited field | `du -sh file \| cut -f1` |
236+
237+
## Archives
238+
239+
| Command | What It Does | Example |
240+
|---------|-------------|---------|
241+
| `tar -czf archive.tar.gz files` | Create gzip-compressed archive | `tar -czf backup.tar.gz *.sh` |
242+
| `tar -xzf archive.tar.gz` | Extract gzip-compressed archive | `tar -xzf backup.tar.gz` |
243+
244+
## Conditional Logic
245+
246+
| Syntax | What It Does |
247+
|--------|-------------|
248+
| `if [ cond ]; then` | Open conditional block |
249+
| `elif [ cond ]; then` | Additional condition |
250+
| `else` | Fallback block |
251+
| `fi` | Close the if block (`if` backwards) |
252+
253+
## Test Operators (Numeric)
254+
255+
| Operator | Meaning | Note |
256+
|----------|---------|------|
257+
| `-eq` | Equal to | `[ $A -eq $B ]` |
258+
| `-ne` | Not equal to | `[ $A -ne $B ]` |
259+
| `-gt` | Greater than | Can't use `>` (it's redirect) |
260+
| `-lt` | Less than | Can't use `<` (it's redirect) |
261+
| `-ge` | Greater than or equal | `[ $A -ge 18 ]` |
262+
| `-le` | Less than or equal | `[ $A -le 100 ]` |
263+
264+
## Test Operators (File)
265+
266+
| Operator | Meaning | Example |
267+
|----------|---------|---------|
268+
| `-f file` | File exists (regular file) | `[ -f notes.txt ]` |
269+
| `-d dir` | Directory exists | `[ -d /etc ]` |
270+
| `-e path` | Path exists (file or dir) | `[ -e /tmp ]` |
271+
199272
## Command Categories Quick Reference
200273

201274
| Need To... | Use |

0 commit comments

Comments
 (0)