✅ WEEK 9: BASH SCRIPTING – COMPLETE SOLUTIONS
Prepared by
Babashaheer
🟢 Level 1 – Beginner
Task 1: Display a Welcome Message
#!/bin/bash echo "Welcome to Bash Scripting!"
Task 2: Read User Name and Greet
#!/bin/bash echo "Enter your name:" read name echo "Hello $name, welcome to Linux!"
Task 3: Show Current Date
#!/bin/bash date
🟡 Level 2 – Intermediate
Task 4: Store and Print Variables
#!/bin/bash course="Network Applications" week=9 echo "Course: $course" echo "Week: $week"
Task 5: Check Voting Eligibility
#!/bin/bash echo "Enter your age:" read age if [ $age -ge 18 ] then echo "You are eligible to vote." else echo "You are not eligible to vote." fi
Task 6: File Existence Check
#!/bin/bash echo "Enter filename:" read file if [ -f "$file" ] then echo "File exists." else echo "File does not exist." fi
🔵 Level 3 – Advanced
Task 7: Create a Log File
#!/bin/bash echo "Log created on:" > system.log date >> system.log whoami >> system.log
Task 8: Loop Through Numbers
#!/bin/bash for i in {1..5} do echo "Number: $i" done
Task 9: Menu-Based Script
#!/bin/bash echo "1. Show Date" echo "2. Show User" read choice case $choice in 1) date ;; 2) whoami ;; *) echo "Invalid option" ;; esac
🔴 Level 4 – Challenge
Task 10: Backup Script
#!/bin/bash backup_dir="backup" mkdir -p $backup_dir cp *.txt $backup_dir echo "Backup completed successfully."
Task 11: Disk Usage Warning
#!/bin/bash usage=$(df / | awk 'NR==2 {print $5}' | sed 's/%//') if [ $usage -gt 80 ] then echo "Warning: Disk usage above 80%" else echo "Disk usage is normal" fi