Skip to content

Variable is not exported when assigned in prefix of call to ()-style function #793

@sckendall2

Description

@sckendall2

To reproduce the bug:

f() { env; }
V=1 f | fgrep -x V=1

In all ksh93 versions I've tried up to and including Version AJM 93u+m/1.0.10 2024-08-01, this snippet prints nothing; the shell doesn't export V into the environment. This behavior contradicts the ksh93 man page:

The environment for any simple-command or function may be augmented by prefixing it with one or more variable assignments... Thus:

TERM=450 cmd args  and
(export TERM; TERM=450; cmd args)

are equivalent...

In other words, the snippet should print V=1. This is what mksh, ksh88, and bash do.

This bug is only with functions defined with the name() syntax. Functions defined with the function name syntax behave correctly.

In fairness, I should note that POSIX section 2.9.1.2 allows either behavior. So it's not implausible to resolve this issue by just documenting the current inconsistent behavior in the man page. But I'd prefer consistency.

Metadata

Metadata

Assignees

No one assigned

    Labels

    1.1Issue relevant to dev branch (v1.1.*)enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions