3 ms·
This is because && and || are often used as conditionals: [ -e README ] && cat README avoids an error if the file README doesn't exist, and [ -e READ
by jks 3y ago
This is because && and || are often used as conditionals:
[ -e README ] && cat README
avoids an error if the file README doesn't exist, and
[ -e README ] || echo "You should write a README!"
works the opposite way.
What's more pernicious is that pipelines don't cause the shell to exit (assuming set -e) unless the last command fails:
grep foo README | sort
does not fail if README doesn't exist, unless you've also used `set -o pipefail`.
- strangesmells02 3y agoso what happens?? it just hang up on the foo??
- osmsucks 3y ago`grep` should terminate with an empty output on `stdout` and an error message on `stderr`, then `sort` will successfully sort the empty contents of `stdout`