News for hackers. Stuff that matters.
Re:When Bash scripts bite by 10165 on Friday May 12, 2017 @12:59AM (#14321543)

    echo ($(ldap-query-for-valid-users)) > /tmp/all-users.sexp
should be something like

    x=$(ldap-query-for-valid-users);
    test ${#x} -gt 0||exec echo no valid users >&2;
    echo \("$x"\) > /tmp/all-users.sexp;
This way they would get the message "no valid users" to stderr and the script would exit. According to the blog post that is what they wanted.

Alternatively,

    x=$(ldap-query-for-valid-users);
    test ${#x} -gt 0||exit 100
    echo \("$x"\) > /tmp/all-users.sexp;
if they prefer a nonzero exit code to a message to stderr.

There are no comments on this comment yet.