ChrisAppStatic v0.4

Bash Functions

What it does: Packages reusable steps with names and arguments—helps keep scripts tidy and testable.

What is it? Functions let you name a block of commands and reuse it. They help keep scripts tidy.

Example: Sum function

#!/bin/bash
sum() {
  local total=0
  for n in "$@"; do
    (( total += n ))
  done
  echo "$total"
}
echo "Sum is: $(sum 3 4 5)"

← Back to home