Donald Feury
Posted on October 23, 2021
In Bash scripts, any command following a &&
will only execute if the previous conditional or command succeeded (returned 0)
The following script will only print out the variable if the conditional succeeds:
[[-z "$1"]] && echo "$1"
On the other hand, any command following a ||
will only execute if the previous conditional or command failed (returned a non zero)
The following script will only print out the variable if the conditional fails:
[[-z "$1"]] || echo "$1"
Related
Did you find this information useful? If so, consider heading over to my donation page and drop me some support.
Want to ask a question or just chat? Contact me here
π πͺ π
π©
Donald Feury
Posted on October 23, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
automation How to automate the launch of your terminal processes (fzf + tmux + teamocil)
November 27, 2024