>_ IzzyLab

Topic breakdown

A function in bash is a named block of code; inside it the call arguments are available as $1, $2, exactly like the script's positional parameters. The crucial point: return in bash hands back only an exit code (0–255), not an arbitrary number, so the convention is for the function to print its "result" to stdout, and the caller captures it with command substitution $(...). The computation itself is done in the arithmetic context $(( ... )). The value captured into a variable is then saved to a file with the > redirection.

What's checked

  1. the square of 7 is 49
  2. the square function works (square 3 → 9)

What it looks like