Stéphane commented that
A && B || Ccannot be used in place of properif then else fi
Can someone explain what's the difference?
Stéphane commented that
A && B || Ccannot be used in place of properif then else fi
Can someone explain what's the difference?
It is very easy to make a mistake in cases like A && B || C.
They are almost universally "write only" - once you wrote such compound statement and it works - it is difficult to change some parts of such statement without loosing the whole logic.
If A or B commands are not a one-word commands - such compound statement can become extremely long and difficult to read, since you would need to horizontally scroll the line.
If A or B - are commands with parameters, then you will have problems with finding && and || in the long lines of words. Again difficulties to understand and maintain.
If you have something like
make && run_test
That is fine. But that is actually an extent of usability. Anything more - better be rewritten to if then fi
A && B || C across multiple lines. I'm use to programming with monads so this is natural https://topaz.github.io/paste/#XQAAAQBOAAAAAAAAAAAFGTH0Q/5dPoIBanK0lQdPubviXoHoVCPrBYPgbwKEW/0peR3Vnsq+h2ewq3AYM9Gst+SO2PKsF3QD/UIcyt//8XYQAA==
– Tom Huntington
Nov 09 '23 at 23:43
&& and ||, just like it does with pipe |. No bashslashes required. If the B and C commands are wrapped in { } or ( ) they can be multi-line as for any other pipeline. Not saying this is a good idea, only that syntax and long lines are not the issue here.
– Paul_Pedant
Nov 10 '23 at 11:08
if A is true but B is false, C will run.– Tom Huntington Jan 15 '24 at 19:41