Fundamentals16 / 17
Up next

Local variables in functions

#!/usr/bin/env bash
greet() {
  # local confines the variable to this function
  local who="$1"
  echo "hello, $who"
}
greet "Ada"
# who is undefined out here, so this prints an empty value
echo "outside: [${who:-unset}]"
What you're solving

local keeps a variable scoped to its function