ChrisAppStatic v0.4

Bash If / Else

What it does: Makes decisions in your script—like branching if files exist or numbers match—so your automation can react to real conditions.

What is it? Conditional logic lets your script take different paths depending on a test—like file exists, command success, or number comparisons.

Example: Check file exists, else create it

#!/bin/bash
FILE="example.txt"
if [[ -f "$FILE" ]]; then
  echo "Found $FILE"
else
  echo "Creating $FILE"
  echo "Hello" > "$FILE"
fi

← Back to home