Re:Filenames and Pathnames in Shell: How to Do It Correctly
by Calzifer on Tuesday June 20, 2023 @07:59AM
(#36402799)
Another variant which I overlooked to often is if you have a construct which returns an error but does not exit the script later move it in a function and now it does exit the script.
will print "Status: 1" but
will print nothing but exit after func returns.
[ Parent
| on HN ]
Re:Filenames and Pathnames in Shell: How to Do It Correctly
by js2 on Tuesday June 20, 2023 @10:11AM
(#36404248)
There's quite a few situations where it does NOT exit when you'd expect it to. This is one of those. What you're seeing there is a variant of the "Short-Circuiting Considerations" discussed here:
http://redsymbol.net/articles/unofficial-bash-strict-mode/
Basically, when you short circuit, it will not cause the script to exit. However, the short circuit still affects the return value of the function, or the script itself if it's the last line of the script.
So your short circuit is causing the function to return non-zero, which then causes the script to exit.