Monday, April 20, 2026
Cohort 3 | Project CloudIgnite Topics: Bash Scripting (Conditionals, Loops, Control Flow), Linux Software Management, Installing AWS CLI Duration: ~3 hours
☁️ AWS Certified Cloud Practitioner (CLF-C02) relevance is flagged throughout with this symbol.
Key Takeaways
- Bash scripting:
#!/bin/bashshebang,if/elif/else/fi,for/while/untilloops,break/continue - Package managers:
yum(Amazon Linux/Red Hat),apt(Ubuntu/Debian) - AWS CLI: Download, unzip, install with
./aws/install, configure withaws configure - Lab: Backup script using
tar -czvfwith date-stamped filenames exitcodes: 0 = success, non-zero = error;$?checks last command's exit code
Table of Contents
- Bash Scripting Recap
- Conditional Statements
- Loops
- Loop Control — break & continue
- Other Bash Concepts
- Lab — Backup Script
- Linux Software Management
- Lab — Installing AWS CLI
- Quiz Review
- CLF-C02 Relevance Summary
1. Bash Scripting Recap
Basic structure
#!/bin/bash # Shebang — always the first line; tells the OS which shell to use
echo "Enter your name:"
read name # Reads input from terminal into variable 'name'
echo "Hello $name"
echo— prints output to terminalread— reads user input into a variable- Variables — no spaces around
=; reference with$varname - Shebang (
#!/bin/bash) — specifies the interpreter; without it, the default shell is used (may vary)
Running a script
chmod +x script.sh # Give execute permission (or use chmod 744)
./script.sh # Run using relative path (dot-slash)
Why
./? Without it, the shell looks for the script inside directories listed in the$PATHvariable, not the current directory.
2. Conditional Statements
Basic if-else syntax
if [ condition ]; then
# do something
else
# do something else
fi # 'fi' closes the if block (reverse of 'if')
if-elif-else (multiple conditions)
if [ $1 -gt $2 ]; then
echo "First number is greater"
elif [ $1 -lt $2 ]; then
echo "Second number is greater"
else
echo "Numbers are equal"
fi
Checking if a file exists
read -p "Enter file name to delete: " filename
if [ -f "$filename" ]; then
echo "Deleting file..."
rm "$filename"
else
echo "File does not exist."
fi
Common comparison operators
| Numeric (bash style) | Symbol equivalent | Meaning |
|---|---|---|
-eq | == | Equal |
-ne | != | Not equal |
-gt | > | Greater than |
-lt | < | Less than |
-ge | >= | Greater than or equal |
-le | <= | Less than or equal |
Tip: The symbol equivalents (
>,<,==) are easier to remember (same as Python/Java/C++). Both styles work in bash.
File test operators
| Flag | Meaning |
|---|---|
-f | Is a regular file |
-e | Exists (file or directory) |
-d | Is a directory |
Exit codes
$?— holds the exit code of the last command0= success; non-zero = failure/error- Useful for checking if a command ran successfully:
cp file1 /tmp
if [ $? -eq 0 ]; then
echo "Copy successful"
fi
Brackets quick reference
| Syntax | Purpose |
|---|---|
[ condition ] | Test / condition (single bracket) |
(( expression )) | Arithmetic / calculation (double parenthesis) |
{ 1..10 } | Range / brace expansion |
3. Loops
For loop
# Explicit list
for file_name in file1 file2 file3 file4; do
touch "$file_name"
done
# Using a range (brace expansion)
for i in {1..10}; do
touch "file$i"
done
While loop
counter=1
while [ $counter -le 5 ]; do
echo "Current value: $counter"
((counter++)) # Increment counter
done
echo "Loop exited"
- Executes as long as the condition is true
- Always increment your counter — forgetting this creates an infinite loop
Until loop
until [ condition ]; do
# runs until condition becomes TRUE
done
- Opposite of
while— runs while condition is false - You can do everything with
for/while;untilis optional to know
while true — infinite loop (use with caution!)
while true; do
read -p "Guess the number: " guess
if [ $guess -eq 7 ]; then
break # Only way out
fi
done
⚠️ An infinite loop without a
breakwill spike CPU usage. Always have an exit condition. Press Ctrl+C to kill a runaway loop.
4. Loop Control — break & continue
break
Exits the loop immediately when a condition is met.
for i in {1..50}; do
if [ $i -eq 10 ]; then
break # Stops at 10, even though loop goes to 50
fi
echo $i
done
continue
Skips the remaining statements in the current iteration and moves to the next one.
for i in {1..15}; do
if [ $i -eq 10 ]; then
continue # Skips printing 10
fi
echo $i
done
# Output: 1 2 3 4 5 6 7 8 9 11 12 13 14 15
Practical note:
breakis used frequently;continueis rarer but useful for skipping specific values.
5. Other Bash Concepts
Exit command
exit 0 # Successful execution
exit 1 # Error occurred (any non-zero = problem)
Command substitution
Embed the output of a command directly into a variable or string:
current_date=$(date +%Y_%m_%d)
echo "Today is $current_date"
printf
Similar to printf in C/Python — formatted output.
Running scripts — path rules
| Command | Where bash looks |
|---|---|
./script.sh | Current directory |
script.sh (no path) | Directories in $PATH variable |
/full/path/script.sh | Exact location |
To make a script runnable from anywhere, add its directory to $PATH.
Vim — show line numbers
:set number # Inside vim, in command mode
Or add set number to ~/.vimrc for it to be permanent.
6. Lab — Backup Script
Task: Write a bash script that creates a compressed backup of a folder named company_a. The archive filename must include today's date in YYYY_MM_DD format.
Solution walkthrough
#!/bin/bash
# Step 1: Get today's date
day=$(date +%Y_%m_%d)
# Step 2: Define the backup file path
backup_name="/home/ec2-user/backups/${day}_backup_company_a.tar.gz"
# Step 3: Create the compressed archive
tar -czvf "$backup_name" /home/ec2-user/company_a
echo "Backup created: $backup_name"
Key tar flags
| Flag | Meaning |
|---|---|
-c | Create archive |
-z | Compress with gzip |
-v | Verbose (show progress) |
-f | Specify filename |
Setup steps
touch backup.sh
chmod +x backup.sh # or: chmod 744 backup.sh
vim backup.sh # Write the script
./backup.sh # Run it
Common mistake: Using
$nameas thermtarget without specifying the path. Userm $(pwd)/$nameor provide the full path.
7. Linux Software Management
Package managers by distribution
| Distribution | Package Manager |
|---|---|
| Red Hat / Amazon Linux | yum (older) or dnf (newer) |
| Debian / Ubuntu | apt (Advanced Package Tool) |
Amazon Linux EC2 instances are based on Red Hat, so use
yumordnf.
Common yum commands
sudo yum check-update # Check for available updates
sudo yum update --security # Apply security updates only
sudo yum upgrade # Upgrade all packages
sudo yum install -y httpd # Install Apache web server (-y = yes to all prompts)
sudo yum history # View install history
sudo yum history info <ID> # Details of a specific install action
sudo yum history undo <ID> -y # Roll back / undo an installation
Two ways to install software on Linux
- Package manager — downloads pre-compiled binary from a repository. Easiest and most common.
- Source code — download source (e.g.,
git clone), compile manually, then install. Slower but gives full control.
Repositories
- A repository is a server that stores packaged (pre-compiled) software.
- Amazon Linux has two main repos: Amazon 2 Core (OS packages) and Amazon 2 Extra (Docker etc.)
- Package manager fetches software from the repo automatically.
Downloading files from terminal (no browser on EC2!)
wget http://example.com/software.zip # Simple download
curl -o software.zip http://example.com/software.zip # More flexible
wgetcan auto-resume interrupted downloads;curlrequires manual flags to do the same.
8. Lab — Installing AWS CLI
Objective: Download, install, and configure the AWS CLI on a Red Hat-based EC2 instance.
Steps
# 1. Check Python is available (AWS CLI v2 requires it)
python3 --version
pip3 --version
# 2. Download AWS CLI zip using curl
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
# 3. Unzip
unzip awscliv2.zip
# 4. Install
sudo ./aws/install
# 5. Verify
aws --version
aws help # Press Q to quit
Configure AWS CLI
aws configure
# AWS Access Key ID: [press Enter — or paste key]
# AWS Secret Access Key: [press Enter — or paste key]
# Default region name: us-west-2
# Default output format: json
Where to find credentials (in AWS lab environment)
- In the lab panel → Details → Show → copy
[default]block including both=signs at the end of the secret key
Save credentials manually
sudo nano ~/.aws/credentials
# Paste the [default] block
# Ctrl+O → Enter (save) → Ctrl+X (exit)
Verify installation
aws ec2 describe-instances \
--instance-ids <your-instance-id> \
--query "Reservations[].Instances[].InstanceType"
If it returns an instance type (e.g., t3.micro), the CLI is working correctly.
☁️ CLF-C02 relevance: AWS CLI is a core tool for interacting with AWS services programmatically — understanding it supports the "Cloud Technology and Services" domain.
9. Quiz Review
| Question | Answer | Why |
|---|---|---|
| Why create a bash script? | Automate repetitive tasks; ensure tasks run correctly and consistently | Built-in data validation is NOT a bash feature |
| First line of a bash script? | #!/bin/bash (shebang) | Specifies the interpreter |
What are $1, $2, $3? | Arguments passed to the script | $0 = script name itself |
| What causes a script to stop and exit the shell? | exit | return exits a function; kill kills a process |
| Which statement defines two courses of action? | if-else | True path and false path |
wget vs curl for resuming downloads? | wget auto-resumes; curl does not by default |
10. CLF-C02 Relevance Summary
The CLF-C02 exam focuses on AWS services and cloud concepts, not deep Linux/bash knowledge. However, the following from today's lecture is relevant:
| Topic | CLF-C02 Domain | Notes |
|---|---|---|
| AWS CLI | Cloud Technology & Services (Domain 3) | Understanding that AWS CLI is a way to interact with AWS programmatically; it must be installed and configured with credentials and a region |
| AWS Regions | Cloud Concepts / Global Infrastructure | Lab used us-west-2 — understanding that resources are region-specific is exam content |
| EC2 Instances | Cloud Technology & Services | The lab ran on an EC2 instance (Linux VM); knowing EC2 is a compute service is tested |
Instance Types (e.g., t3.micro) | Cloud Technology & Services | Instance types determine compute capacity/cost — relevant to understanding EC2 pricing tiers |
| AWS Access Keys / IAM credentials | Security & Compliance (Domain 2) | AWS CLI uses Access Key ID + Secret Access Key; these are IAM credentials — security best practices around keys are tested |
| Package managers / Software installation | Not directly tested | Background knowledge useful for working with EC2, but not an exam topic |
| Bash scripting | Not directly tested | Not an exam topic, but automation concepts relate to AWS tools like AWS Systems Manager and Lambda |
💡 Study tip (from the instructor): For the CLF-C02, focus your energy on knowing AWS services — what each service does, when to use it, and roughly how it's priced. Linux and Python questions will be minimal on that exam.
Key Takeaways
- Bash scripting is a core DevOps skill — you don't need to memorize all syntax; understand the concepts and look up syntax when needed.
- Conditionals (
if/elif/else/fi), loops (for/while), and exit codes (0= success) are the essential building blocks. - Use
./script.shto run scripts in the current directory; add to$PATHto run from anywhere. - On Red Hat/Amazon Linux, use
yumfor package management;aptis for Debian/Ubuntu. - AWS CLI is installed via
curl+unzip+./aws/installand configured withaws configure. - Always specify the correct AWS region when configuring the CLI — it must match where your resources are running.
Notes compiled from lecture — April 20, 2026 · Cohort 3: Project CloudIgnite