質問

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

if [ … ]; then
do

over using short-circuit list evaluators with command groups such as

[ … ] && {
}

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

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

役に立ちましたか?

解決

Not with your example, but the commonly seen

condition && foo || bar

is not the same as

if condition
then
  foo
else
  bar
fi

In the former case, bar will run not only if condition fails, but if foo fails.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top