3 ms·
Is this really so much worse: { test -f a && test -f b; } || { test -f c && test -f d; } ? Yes, it's more verbose, but the original expression isn't parti
by sltkr 6y ago
Is this really so much worse:
{ test -f a && test -f b; } || { test -f c && test -f d; }
?
Yes, it's more verbose, but the original expression isn't particularly readable either, and if you'd want to evaluate something like (a OR b) AND (c OR d) you'd need to introduce parentheses anyway.
- hvdijk 6y agoNote also that this does not need any subshells. I think dataflow was thinking of (test -f a && test -f b) || (test -f c && test -f d) instead, but { } isn't worse than that.
- dataflow 6y agoYeah almost. I was thinking of ([ -f a ] && [ -f b ]) || ([ -f c ] && [ -f d ]) instead of (test -f a && test -f b) || (test -f c && test -f d)
- dolmen 6y agoParentheses launch a subshell, so you probably want to use accolades instead: {[ -f a ] && [ -f b ] ;} || { [ -f c ] && [ -f d ] ;}
- dataflow 6y agoWith braces I'd prefer the test syntax actually, this is too many special characters to be comfortably readable for me. And yes I know it creates subshells, that was precisely what I was saying in my comment where I said the simplest syntax I could think of (i.e. that very code) creates subshells.
- dataflow 6y agoIt's not "so much" worse, it's just mildly worse. All I was saying here was the verbosity is a reason for using them. Obviously there are reasons not to use them too, which I said in my own top comment.