A && B || C vs if then else fi

St├ęphane commented that

A && B || C cannot be used in place of proper if then else fi

Can someone explain what’s the difference?

Asked By: Tom Huntington

||

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

Answered By: White Owl
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.