Skip to content

Scripting

8 min

Functions, and why local matters

Without it, every assignment is global.

A function shares the shell's variables. An assignment inside one is global unless it says otherwise, which is how a helper quietly overwrites its caller's loop variable.

local fixes that, and restores the previous value on return — including restoring it to not existing if it did not exist before.

Try this

return sets the function's exit status, which is what the caller sees in $?. A function has no other return value: to hand back data, print it and let the caller capture it with $( ).

Try this

$

Files

The files in the sandbox, with their modes, link counts and sizes
ModeLinksSizeName
-rw-r--r--198manifest.md
-rw-r--r--169summary.txt