top | item 38393736

(no title)

jeramey | 2 years ago

Yes, there is. To negate, just use ! as with many other languages.

    if ! command …; then
        do_needed_things
    fi

discuss

order

ramshorns|2 years ago

How does that work? It doesn't look like ! is a command or shell builtin, so I guess it's an argument to if.

mkl|2 years ago

No, it's part of the shell. Do "man bash" or "man sh", then search with "/\!". From man bash: "If the reserved word ! precedes a pipeline, the exit status of that pipeline is the logical negation of the exit status".

hibbelig|2 years ago

Amazing! I've been writing shell scripts since the 90s and now I still learn something new. Thank you!