|
| 1 | +# Basic Shell Scripting Examples |
| 2 | + |
| 3 | +This folder contains **basic Bash shell scripting examples** for beginners. |
| 4 | +Each script demonstrates a core concept commonly used in shell scripting. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## Prerequisites |
| 9 | + |
| 10 | +* Linux / macOS terminal (or Git Bash / WSL on Windows) |
| 11 | +* Bash shell |
| 12 | +* Basic terminal knowledge (`cd`, `ls`) |
| 13 | + |
| 14 | +Make scripts executable (optional): |
| 15 | + |
| 16 | +```bash |
| 17 | +chmod +x *.sh |
| 18 | +``` |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## Scripts Overview |
| 23 | + |
| 24 | +### 1️⃣ `variables.sh` |
| 25 | + |
| 26 | +**What it demonstrates** |
| 27 | + |
| 28 | +* How to declare and use variables in Bash |
| 29 | + |
| 30 | +**How to run** |
| 31 | + |
| 32 | +```bash |
| 33 | +bash variables.sh |
| 34 | +``` |
| 35 | + |
| 36 | +**What you should learn** |
| 37 | + |
| 38 | +* Variable assignment syntax |
| 39 | +* How to reference variables using `$` |
| 40 | +* Difference between strings and variables |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +### 2️⃣ `echo.sh` |
| 45 | + |
| 46 | +**What it demonstrates** |
| 47 | + |
| 48 | +* Printing output to the terminal using `echo` |
| 49 | + |
| 50 | +**How to run** |
| 51 | + |
| 52 | +```bash |
| 53 | +bash echo.sh |
| 54 | +``` |
| 55 | + |
| 56 | +**What you should learn** |
| 57 | + |
| 58 | +* How to display text |
| 59 | +* How to print variables |
| 60 | +* Basic output formatting |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +### 3️⃣ `if_else.sh` |
| 65 | + |
| 66 | +**What it demonstrates** |
| 67 | + |
| 68 | +* Conditional logic using `if`, `else` |
| 69 | + |
| 70 | +**How to run** |
| 71 | + |
| 72 | +```bash |
| 73 | +bash if_else.sh |
| 74 | +``` |
| 75 | + |
| 76 | +**What you should learn** |
| 77 | + |
| 78 | +* How conditions work in Bash |
| 79 | +* Using comparison operators |
| 80 | +* Controlling script flow based on conditions |
| 81 | + |
| 82 | +--- |
| 83 | + |
| 84 | +### 4️⃣ `loops.sh` |
| 85 | + |
| 86 | +**What it demonstrates** |
| 87 | + |
| 88 | +* Looping with `for` (and/or `while`) |
| 89 | + |
| 90 | +**How to run** |
| 91 | + |
| 92 | +```bash |
| 93 | +bash loops.sh |
| 94 | +``` |
| 95 | + |
| 96 | +**What you should learn** |
| 97 | + |
| 98 | +* Repeating commands using loops |
| 99 | +* Iterating over values |
| 100 | +* Automating repetitive tasks |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +### 5️⃣ `hello.sh` |
| 105 | + |
| 106 | +**What it demonstrates** |
| 107 | + |
| 108 | +* A simple end-to-end Bash script |
| 109 | + |
| 110 | +**How to run** |
| 111 | + |
| 112 | +```bash |
| 113 | +bash hello.sh |
| 114 | +``` |
| 115 | + |
| 116 | +**What you should learn** |
| 117 | + |
| 118 | +* Basic script structure |
| 119 | +* Using `echo` |
| 120 | +* Running a shell script from the terminal |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +## Notes |
| 125 | + |
| 126 | +* These examples are intentionally simple for learning purposes. |
| 127 | +* Try editing the scripts and re-running them to better understand how Bash works. |
| 128 | + |
| 129 | +Happy scripting! 🚀 |
0 commit comments