Bug 10936 - Variable assignment with function invocation persists
Summary: Variable assignment with function invocation persists
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-04-10 12:19 UTC by /df
Modified: 2018-08-05 09:16 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
Patch from DASH (711 bytes, text/plain)
2018-04-10 21:57 UTC, /df
Details

Note You need to log in before you can comment on or make changes to this bug.
Description /df 2018-04-10 12:19:24 UTC
Variable assignments on a command line invoking a shell function persist in the local environment, eg:

BusyBox v1.22.1 (Ubuntu 1:1.22.0-15ubuntu1) built-in shell (ash)
Enter 'help' for a list of built-in commands.

~ $ expecting() {
> echo "Expecting ${EXP:-0}"
> }
~ $ expecting
Expecting 0
~ $ EXP=1 expecting
Expecting 1
~ $ expecting
Expecting 1
~ $

This behaviour is to be modified in DASH to match its manual page, which says

"...
The variables which are explicitly placed in the environment of
the command (by placing assignments to them before the function name)
are made local to the function and are set to the values given. ..."

by the patch at https://www.mail-archive.com/dash@vger.kernel.org/msg01579.html, as attached. The undesirable persistent behaviour was apparently a former POSIX requirement.

In case people expect busybox/ash, which I don't think has its own man page, to behave in this way, can a similar change be applied to Busybox?

The affected lines in Busybox are shell/ash.c:10199 for the first change and shell/ash.c:9564-6 for the second.
Comment 1 /df 2018-04-10 21:57:53 UTC
Created attachment 7556 [details]
Patch from DASH
Comment 2 Denys Vlasenko 2018-04-11 10:42:33 UTC
Not in dash git yet.
Comment 3 Denys Vlasenko 2018-08-05 09:16:34 UTC
Fixed in git.