Re: Bash true/false builtings undocumented? "false" not working?
-----BEGIN PGP SIGNED MESSAGE-----
On Fri, Aug 17, 2018 at 10:12:54AM -0400, Greg Wooledge wrote:
> On Fri, Aug 17, 2018 at 03:43:58PM +0200, email@example.com wrote:
> > The construction
> > foo && echo "bar" || echo "baz"
> > does probably work, because echo's exit status is (always?) 0 (the bash
> > builtin's documentation mumbles something about "write error").
> echo can fail if stdout is closed, or if it's redirected to a file that
> can't be written to (because of a full disk, etc.).
> Sure, it may work 99.99% of the time, but it's still not safe.
This particular idiom is still fine, since if stdout gets closed,
nobody will notice the difference between both branches anyway .
I still maintain that this pattern is OK, since it's idiomatic and
highly readable. But of course, you gotta know what you're doing,
and in which ways it may break down. And blog pages like yours are
invaluable in that (although we may disagree (methodically( somewhat
in this point, I am thankful that you go to the length of writing
out those things in a generally accessible manner).
Shell only looks simple at first sight. It's a nice "little language",
full of surprises and treasures. But it has to be treated with
somewhat (much) tongue-in-cheek :-P
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
-----END PGP SIGNATURE-----