Skip to content

env: keep a leading = in values attached to short options - #15838

Open
MannXo wants to merge 1 commit into
uutils:mainfrom
MannXo:fix/15754-env-short-option-equals
Open

MannXo wants to merge 1 commit into
uutils:mainfrom
MannXo:fix/15754-env-short-option-equals

Conversation

@MannXo

@MannXo MannXo commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

clap strips a = that starts a value attached to a short option, so env -C=/etc pwd ran in /etc instead of ./=/etc. The same went for -a=NAME, clustered forms like -vC=/etc, and -S'-C=/etc pwd'. -C= failed with "cannot change directory to ''", and -vu=FOO unset FOO and exited 0 where GNU rejects it.

The arguments are now passed through preserve_attached_equals before clap, the same approach as preserve_prefix_equals in fmt. It doubles the = after -a, -C or -u so that clap's stripping leaves the value intact. It stops at the first operand or -- and skips detached option values, so arguments meant for the command are untouched. A -u value starting with = now reaches the existing invalid-name check, so the cluster form fails with 125 like -u=FOO already did.

$ mkdir -p /tmp/w/=/etc && cd /tmp/w && env -C=/etc pwd
/private/tmp/w/=/etc
$ env -a=name sh -c 'echo $0'
=name
$ FOO=1 env -vu=FOO true; echo $?
env: cannot unset '=FOO': Invalid argument
125

test_short_option_attached_value_keeps_leading_equals and the new -vu= case in disallow_equals_sign_on_short_unset_option fail on main.

Closes #15754

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

env: -C drops leading equals sign from attached value, unlike GNU

1 participant