Junio C Hamano <[email protected]> writes:

> One thing I was wondering about the $(( ... )) syntax while reading
> this thread was about the SP around the expression, i.e.
>
>       var=$(( $term1 * $term2 + $term3 ))
>
> vs
>
>       var=$(($term1 * $term2 + $term3))
>
> I personally do not have strong preference between the two, but I
> have a vague impression that we preferred the former because
> somebody in the past gave us a good explanation why we should.
>
> "git grep" however seems to tell us that we are not clearly decided
> between the two, so I probably am misremembering it and there is no
> preference either way.

One thing that is somewhat related is that we would want to avoid
writing things like this by mistake:

        var=$((cmd1 && cmd2) | cmd3)

which is not meant to be an arithmetic expansion, but is a command
substitution that happens to have a subshell at the head of the
pipeline.  I think bash gets this right, but some shells (e.g. dash)
tries to parse this as an arithmetic expansion upon seeing "$((" and
fails to parse it, waiting forever until it sees the matching "))".
So we write it like this to make it safer:

        var=$( (cmd1 && cmd2) | cmd3 )

Perhaps having a SP after $(( of a real arithmetic expression, i.e.

        var=$(( ... anything ... ))

makes it easier to tell these two apart?  I dunno.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to