Keep function internals from leaking into caller scope.
Section: Functions
Use local variable in function
bash
bash
work() { local dir=${1:-/tmp}; cd "$dir" || return 1; pwd; }Explanation
local is a Bash builtin, not POSIX sh.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Functions