Functional difference between if-then and command

Is there a functional advantage to using a simple if-then statement such as

if [ … ]; then do 

using short circuit list evaluators with commands such as

 [ … ] && { } 

Of course, if then the standard way of recording, but is there any actual difference / advantage from a functional point of view?

Using () instead of {} will create a new subshell, creating a new scope for variables inside the if-then block.

+4
source share
1 answer

Not with your example, but with generally accepted

 condition && foo || bar 

does not match

 if condition then foo else bar fi 

In the first case, bar will be executed not only if condition fails, but if foo fails.

+1
source

Source: https://habr.com/ru/post/1490146/


All Articles