mrsh
mrsh copied to clipboard
Potentially inconsistent wordsplitting behaviour on export assignment
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.
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
)
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]
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.
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").
on [p]bosh, yash
zsh >> bosh test.sh
[contains]
zsh >> pbosh test.sh
[contains]
zsh >> yash test.sh
[contains]
zsh >>