From: Rudolf Polzer <divverent@xonotic.org>
To: dash@vger.kernel.org
Subject: Bug: temporary assignments vs shell function
Date: Thu, 14 Jul 2011 10:34:56 +0200 [thread overview]
Message-ID: <20110714083455.GA25362@div0.qc.to> (raw)
Hi,
I noticed a little bug:
func()
{
echo "Inside the shell function, foo is $foo"
}
foo=foo
foo=bar func
echo "foo is now $foo"
will export foo=bar in global scope (i.e. it affects the execution environment
after the function call).
This is inconsistent with calls to commands (both built-in and external). In
both cases, the variable assignment does not affect the execution environment
after the command.
In SUSv3, I only can find:
| 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).
A shell function however isn't a "special built-in" and also counts as a
"command name", thus the last echo line really should output "foo is now foo",
which it does in e.g. bash and the FreeBSD /bin/sh.
I tried this with current git master, too, and saw no difference, so I suppose
this bug is still open.
What makes this difficult, is that the execution environment of the function is
the SAME as the execution environment of the rest of the script, as neither a
subshell nor a new process is spawned. In a way, this passage of SUSv3 can be
seen as contradictory: the execution environment of the command, and the
current execution environment, are the same, and thus the assignment would have
to both affect the current environment, and not affect it, at the same time
("Schrödinger's Execution Environment"). Most other shells however resolve
this in "some" way so that the called command sees the assignments, and after
the command completes, the assignments are "undone", and I would like dash to
do the same.
Best regards,
Rudolf Polzer
next reply other threads:[~2011-07-14 9:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-14 8:34 Rudolf Polzer [this message]
2011-07-14 9:26 ` Bug: temporary assignments vs shell function Jonathan Nieder
2011-07-14 10:09 ` Rudolf Polzer
2011-07-14 10:25 ` Jonathan Nieder
2011-07-31 22:19 ` Jilles Tjoelker
2011-08-01 5:59 ` Rudolf Polzer
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=20110714083455.GA25362@div0.qc.to \
--to=divverent@xonotic.org \
--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