A comprehensive collection of Bash scripting challenges, organized from beginner to advanced levels. Each challenge tests different aspects of Bash programming, from basic string manipulation to complex system orchestration.
mkdir -p: Creates parent directories as needed (no error if existing)read -p: Displays a prompt before reading inputcp -p: Preserves permissions, ownership, and timestampsbash -c: Executes the command passed as a stringwc -c: Counts bytes in a filetar -c: Creates a new archivecp -v: Verbose mode (shows what the command is doing)rm -f: Forces deletion without confirmationcp -r: Recursive copy (directories and subdirectories)ls -a: Shows hidden files (including dotfiles)ls -l: Long listing format (permissions, ownership, size, date)
- String Reverser – Ultra-Short Bash Edition
- Reverse a String – Bash Golf Edition
- Prime or Not?
- CSV Aggregator – One-Liner Edition
- Days Between Two Dates
- Days Between Two Dates – Pure Bash (Using
dateCommand) - CSV Group & Sum – Amount Only
- The Phantom C Compiler – Find and Compile Hidden C Code
- Bitcoin Price Fetcher – Pure Bash API Call
- XML to JSON Converter
- NGINX Load Balancer Config Generator
- Prometheus & Grafana Bootstrap Generator
- Echoes of the Heptagon – Find Longest Palindromic Wave
- ArgoCD Application Manifest Processor
- ArgoCD Fragmented Application Processor
- Bash 4.0+
Check with:bash --version
name="Basuru"
age=17
echo "My name is $name"=
read -p "Enter your name: " name
echo "Hello $name"today=$(date)
echo "Today is $today"if [ $age -ge 18 ]; then
echo "Adult"
else
echo "Minor"
fiif [ -f file.txt ]; then
echo "File exists"
fi
if [ -d folder ]; then
echo "Directory exists"
fiif [ "$name" == "Basuru" ]; then
echo "Welcome"
fifor i in 1 2 3 4 5; do
echo $i
donecount=1
while [ $count -le 5 ]; do
echo $count
((count++))
donefor file in *.txt; do
echo $file
donegreet() {
echo "Hello $1"
}
greet Basurucheck_file() {
[ -f "$1" ]
}
check_file test.txt && echo "Exists"echo "Script name: $0"
echo "First arg: $1"
echo "All args: $@"Run:
./script.sh file.txtif [ $# -lt 1 ]; then
echo "Usage: $0 filename"
exit 1
ficommand
echo $?set -ebash -x script.shgrep "error" logfile.txtawk '{print $1}' file.txtsed 's/old/new/g' file.txtcommand > out.txt
command >> out.txt
command 2> error.txt
command &> all.txtps aux | grep rootcrontab -eExample:
0 2 * * * /path/backup.shSince you're doing AWS & DevOps, learn these:
aws s3 ls
aws ec2 describe-instances#!/bin/bash
tar -czf backup.tar.gz /data
aws s3 cp backup.tar.gz s3://my-bucket/df -h
free -m
uptimeAlways use:
#!/usr/bin/env bash
set -euo pipefailUse quotes:
"$var"Follow naming conventions:
readonly SCRIPT_DIR