mrsh icon indicating copy to clipboard operation
mrsh copied to clipboard

Potentially inconsistent wordsplitting behaviour on export assignment

Open Earnestly opened this issue 4 years ago • 5 comments

According to wooledge it is possible that a shell may induce wordsplitting on export assignment if the expansion isn't properly quoted (the example is for local but mentions the case is the same for export). The wiki claims dash is susceptible to this but I did not encounter the behaviour:

#!/bin/sh --
var='contains spaces'
export ENVAR=$var
printf '[%s]\n' "$ENVAR"
% for shell in bash dash sh zsh mksh mrsh; do printf '%s: ' "$shell"; "$shell" foo.sh; done
bash: [contains spaces]
dash: [contains spaces]
sh: [contains spaces]
zsh: [contains spaces]
mksh: [contains spaces]
mrsh: [contains]

Of the shells I have, mrsh is the only one which exhibits the behaviour wooledge suggests is possible but I'm unsure if this is a bug or merely a different interpretation of POSIX.

Earnestly avatar Mar 26 '20 09:03 Earnestly

On dash:

> dash
$ v='a b c'
$ export a=$v
$ echo $a
a

Are you sure you're running the script with the correct shell? (ie. dash script.sh instead of running ./script.sh in dash)

emersion avatar Mar 26 '20 09:03 emersion

That's right. You should be able to see the exact command line I used in the original report which calls "$shell" foo.sh where foo.sh is the script I used.

What you're seeing is also something shbot on freenode.net/#bash gets when using the #sh trigger (which uses dash) so perhaps there is a version difference? My dash is currently 0.5.10.2

In an interactive session I also get:

% dash
$ a='b c'
$ export e=$a
$ printf '[%s]\n' "$e"
[b c]

Earnestly avatar Mar 26 '20 10:03 Earnestly

I realised that I was using dash built from git. After some use of bisect I landed upon this commit which addresses the issue of export fairly explicitly.

The commit message notes a recent change in POSIX but I'm not familiar, especially the "semantics are now much better defined." part.

Earnestly avatar Mar 26 '20 14:03 Earnestly

Makes sense. It seems like mrsh's behavior is POSIX-compliant at least for now. I'll leave this open just to remember about all of this (the dash commit says it'll become POSIX "soon").

emersion avatar Mar 30 '20 16:03 emersion

on [p]bosh, yash

zsh >> bosh test.sh
[contains]
zsh >> pbosh test.sh
[contains]
zsh >> yash test.sh
[contains]
zsh >>

illiliti avatar Apr 13 '20 20:04 illiliti