dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nico Huber <nico.h@gmx.de>
To: dash@vger.kernel.org
Subject: export statements and command substitution
Date: Sun, 24 Jul 2016 15:46:02 +0200	[thread overview]
Message-ID: <5e6f29ec-418c-32f9-7754-5a4fe1f66577@gmx.de> (raw)

Hi dash folks,

we stumbled over a little curiosity in dash's behavior when you combine
a variable assignment within an export statement with command sub-
stitution.

The following works fine in bash:
  $ export foo=$(echo foo bar)
  $ echo $foo
  foo bar
dash, however, applies field splitting and thus takes `bar` as a second
variable name:
  $ export foo=$(echo foo bar)
  $ echo $foo
  foo
which can easily be fixed by adding double quotes:
  $ export foo="$(echo foo bar)"
  $ echo $foo
  foo bar

I know bash shouldn't be the reference so I had a look at [1]. It
states:
 "If a command substitution occurs inside double-quotes, field
  splitting and pathname expansion shall not be performed on the
  results of the substitution."
Which one could read as field splitting should take place if you don't
supply double quotes. But in present shells variable assignments seem
to be an exception.

And even dash doesn't apply field splitting on a simple assignment:
  $ foo=$(echo foo bar)
  $ echo $foo
  foo bar

That's at least inconsistent and, IMO, the export statement should have
the same semantics (i.e. not requiring double quotes) as things can get
quite nasty if you think of evaluations like:
  $ export foo=$(echo bar bar=foo)
  $ echo $foo
  bar
  $ echo $bar
  foo

Best regards,
Nico

[1]
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_03

             reply	other threads:[~2016-07-24 13:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-24 13:46 Nico Huber [this message]
2016-07-24 14:05 ` export statements and command substitution Harald van Dijk

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=5e6f29ec-418c-32f9-7754-5a4fe1f66577@gmx.de \
    --to=nico.h@gmx.de \
    --cc=dash@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).