Scripting
8 minFunctions, 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
| Mode | Links | Size | Name |
|---|---|---|---|
| -rw-r--r-- | 1 | 98 | manifest.md |
| -rw-r--r-- | 1 | 69 | summary.txt |