# Shell Script Conditionals and Loops for Beginners
**(Week 3 – Cohort 3 Bootcamp)**
Shell scripting is a practical way to automate tasks and control system behavior in Linux. If you're new to it just like me, one of the first things you'll use are **conditionals** and **loops**. These control how and when your script runs certain commands.
This article summarizes my Week 3 learning experience at the Web2 Bootcamp (Cohort 3). I worked with conditionals and loops, wrote functional scripts, and got comfortable using Bash for basic automation.
## CONDITIONALS
Conditionals are used to make decisions in your script. They let the script choose actions based on whether a condition is true or false.
### 1. `if` Statement
Used to test a condition. If the condition is true, the code block runs.
### 2. `if-else`
Adds an alternative block that runs if the condition is false.
### 3. `elif`
Short for "else if". Lets you test multiple conditions in sequence.
### Truth Table for Conditionals
Condition Result
| true | Executes `then` block |
| -------- | -------- |
| false | Skips `then`, checks next (`elif` or `else`)
## LOOPS
Loops let your script repeat actions multiple times, either for a set number of items or while a condition remains true.
### 1. `for` Loop
Used to loop over a list of values like numbers, filenames, or words.
### 2. `while` Loop
Keeps running a set of commands as long as a condition stays true.
### What I feel was easy and can be easy for Beginners like Myself
* Writing basic `if` and `else` logic
* Looping through simple lists with `for`
* Using numeric comparisons like `-eq`, `-gt`, `-lt`
* Building readable and structured scripts
### What I feel Might Difficult to learn as a Beginner
* Remembering to put spaces inside `[ ]` when writing conditions
* Quoting variables properly to avoid unexpected results
* Nesting loops and conditionals together
* Handling invalid input or writing robust validation logic
## Common Comparison Operators for shell scripting
| Operator | Description |
|----------|--------------------|
| `-eq` | Equal to |
| `-ne` | Not equal to |
| `-gt` | Greater than |
| `-lt` | Less than |
| `-ge` | Greater or equal |
| `-le` | Less or equal |
| `&&` | Logical AND |
| `\|\|` | Logical OR |
## Examples I used for Practice
### Example 1: Grade Checker Script





### Example 2: Car Engine Log Script






### Example 3: Password Verification Script


This week, I practiced how to control script flow using conditionals and loops. These examples helped add up my knowlede and skill on logic building and gave me real insights into how Bash scripting works in practical scenarios. I'm so excited about learning shell scripting. It can only get better.