dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Harald van Dijk <harald@gigawatt.nl>, dash <dash@vger.kernel.org>
Subject: Re: [PATCH] Fix variable assignments in function invocations
Date: Fri, 09 Jan 2015 10:39:14 -0700	[thread overview]
Message-ID: <54B01242.9000907@redhat.com> (raw)
In-Reply-To: <54B00D36.7070707@gigawatt.nl>

[-- Attachment #1: Type: text/plain, Size: 2379 bytes --]

On 01/09/2015 10:17 AM, Harald van Dijk wrote:
> Hello all,
> 
> A long-standing problem with dash has been how it deals with variable
> assignments in function invocations, and several packages are affected
> by it, two I've come across recently being autogen and pkg-config (only
> their test suites, luckily).
> 
> A short test script:
> 
>   f() {
>     echo inside f, VAR is $VAR
>     sh -c 'echo inside sh called from f, VAR is $VAR'
>   }
> 
>   VAR=value f

This behavior is tricky.  Here's the latest POSIX wording:
http://austingroupbugs.net/view.php?id=654#c1559

      * If the command name is a function that is not a standard
        utility implemented as a function, variable assignments shall
        affect the current execution environment during the execution
        of the function. It is unspecified:

          - Whether or not the variable assignments persist
            after the completion of the function

          - Whether or not the variables gain the export
            attribute during the execution of the function

          - Whether or not export attributes gained as a result of the
            variable assignments persist after the completion of
            the function (if variable assignments persist after the
            completion of the function)

So the existing dash behavior is compliant, even if different from bash.

> 
> Quoting SUSv4 Shell Command Language 2.9.1 Simple Commands:
> 
>   If no command name results, variable assignments shall affect the
>   current execution environment. Otherwise, the variable assignments
>   shall be exported for the execution environment of the command and
>   shall not affect the current execution environment (except for
>   special built-ins).

This is the text that was rendered obsolete by the above POSIX bug 654.

> Fixing this seems trivial, see the attachment, and the test suites of
> both autogen and pkg-config pass with this change. Does this look correct?

I have no opinion on whether to take the patch in order to behave more
like bash, or whether to tell script-writers to fix their script to
avoid unspecified behavior because dash is already compliant in
providing a different behavior than bash.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2015-01-09 17:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-09 17:17 Harald van Dijk
2015-01-09 17:39 ` Eric Blake [this message]
2015-01-09 17:55   ` Harald van Dijk
2015-01-09 19:36   ` Chet Ramey

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=54B01242.9000907@redhat.com \
    --to=eblake@redhat.com \
    --cc=dash@vger.kernel.org \
    --cc=harald@gigawatt.nl \
    --subject='Re: [PATCH] Fix variable assignments in function invocations' \
    /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

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).