Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
jeramey
on Nov 23, 2023
|
parent
|
context
|
favorite
| on:
test, [, and [[ (2020)
Yes, there is. To negate, just use ! as with many other languages.
if ! command …; then do_needed_things fi
ramshorns
on Nov 23, 2023
|
next
[–]
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
on Nov 23, 2023
|
parent
|
next
[–]
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
on Nov 23, 2023
|
prev
[–]
Amazing! I've been writing shell scripts since the 90s and now I still learn something new. Thank you!
Consider applying for YC's Spring batch! Applications are open till Feb 11.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: