- Posted on
- Featured Image
When using `local var=$(cmd)` in bash functions, the exit code of `cmd` is overridden by the exit code of the `local` command, which often returns 0. To preserve the exit status of `cmd`, first declare the variable with `local output`, then assign separately with `output=$(cmd)`. This ensures correct capture of the exit status.