From: Junio C Hamano <junio@pobox•com>
To: John Keeping <john@keeping•me.uk>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx•de>,
git@vger•kernel.org, Elia Pinto <gitter.spiros@gmail•com>
Subject: Re: [PATCH 0/3] Fix $((...)) coding style
Date: Thu, 04 Feb 2016 11:43:58 -0800 [thread overview]
Message-ID: <xmqqtwlogt1d.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: 20160204155316.GI29880@serenity.lan
Junio C Hamano <gitster@pobox•com> 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.
prev parent reply other threads:[~2016-02-04 19:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-04 12:01 [PATCH 0/3] Fix $((...)) coding style Johannes Schindelin
2016-02-04 12:02 ` [PATCH 1/3] filter-branch: fix style of $((...) construct Johannes Schindelin
2016-02-04 12:02 ` [PATCH 2/3] rebase--interactive: adjust the coding style of $((...)) Johannes Schindelin
2016-02-04 12:03 ` [PATCH 3/3] rebase --merge: adjust $((...)) coding style Johannes Schindelin
2016-02-04 12:14 ` [PATCH 0/3] Fix " John Keeping
2016-02-04 12:38 ` Johannes Schindelin
2016-02-04 13:01 ` John Keeping
2016-02-04 13:13 ` Johannes Schindelin
2016-02-04 14:06 ` John Keeping
2016-02-04 15:27 ` Johannes Schindelin
2016-02-04 15:53 ` John Keeping
2016-02-04 19:43 ` Junio C Hamano
2016-02-04 19:43 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqtwlogt1d.fsf@gitster.mtv.corp.google.com \
--to=junio@pobox$(echo .)com \
--cc=Johannes.Schindelin@gmx$(echo .)de \
--cc=git@vger$(echo .)kernel.org \
--cc=gitter.spiros@gmail$(echo .)com \
--cc=john@keeping$(echo .)me.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox