Bash Scripting Cheat Sheet

Last Updated: November 21, 2025
⏰ Interactive Tool

Build and understand cron schedules with our Cron Expression Helper

Script Basics

#!/bin/bash

# Variables
name="John"
count=5

# If statement
if [ $count -gt 3 ]; then
    echo "Count is greater than 3"
fi

# For loop
for i in {1..5}; do
    echo "Number: $i"
done

# Functions
function greet() {
    echo "Hello $1"
}
greet "World"

Common Patterns

$1, $2, $3
Script arguments
$@
All arguments
$?
Exit status of last command
$#
Number of arguments
$(command)
Command substitution
💡 Pro Tip: Always quote variables: "$var" prevents word splitting!
← Back to DevOps & Cloud | Browse all categories | View all cheat sheets