Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I call this the "disabled errexit quirk" which leads to the "if myfunc" pitfall:

https://www.oilshell.org/release/latest/doc/error-handling.h...

Here's a demo of how Oil fixes it, which I mentioned in this thread:

    $ osh hn.sh
    a-b-True
You can add shopt --set strict_errexit at the top of your script:

    $ osh -o strict_errexit hn.sh
      if myfun; then
      ^~
    hn.sh:3: errexit was disabled for this construct

    if myfun; then
       ^~~~~
    hn.sh:3: fatal: Can't run a proc while errexit is disabled. Use 'try' or wrap it in a process with $0 myproc
Or just use Oil:

    $ oil hn.sh
    <same output>
So Oil is acting like a ShellCheck at runtime, to unconditionally flag this error. It cannot be caught using syntax (which ShellCheck is limited to), because function vs. external executable is a runtime decision.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: