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

Not that people should be expected to know this, but here's an idiom that does work:

    if res="$(ldap-query-for-valid-users)"; then
        echo "($res)" > "/tmp/all-users.sexp"
    else
        handle_failure
    fi
    
I second the recommendation to use https://github.com/koalaman/shellcheck – you really shouldn't be writing shell scripts without it – but in this case it doesn't seem to handle the issue (with default settings at least).


Since 'set -e' is used already, a simpler variation is sufficient:

  result=$(ldap-query-for-valid-users)
  echo "($result)" > "/tmp/all-users.sexp"
Decoupling the process substitution from another invocation allows the error to be detected.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

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

Search: