local - create a function-local variable
local [-i] NAME[=VALUE]...
Options you will use
-a- The variable is an indexed array.
-A- The variable is an associative array (keys are strings).
-i- The variable is an integer: assignments are evaluated as arithmetic.
-n- A nameref: the variable is another name for the variable named in its value.
-r- Read-only.
Gotchas
local x=$(cmd)swallows cmd's exit status, because the status you get islocal's. Split it:local x; x=$(cmd). shellcheck SC2155.
Try local in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.