-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Fri, Aug 17, 2018 at 10:12:54AM -0400, Greg Wooledge wrote: > On Fri, Aug 17, 2018 at 03:43:58PM +0200, to...@tuxteam.de 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 [1]. 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 respect :-) Cheers [1] https://en.wikipedia.org/wiki/If_a_tree_falls_in_a_forest somewhat (much) tongue-in-cheek :-P - -- t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlt23XsACgkQBcgs9XrR2kb7iQCeKCaitOt1MKnBXgRikIdA5LHR BsoAn2i1Whwel4Qx4RIIm5bCBA0ItpI9 =oBeC -----END PGP SIGNATURE-----