[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: $*/$@/$IFS and Bourne vs Almquist vs Korn vs mksh



On Wed, 15 Oct 2014, Stephane Chazelas wrote:

> $ mksh -c 'IFS=; x=abc; printf "<%s>\n" ${x#$*}' x a b | sed -n l
> <\a\300a>$
> <abc>$

Interesting… but all shells diverge on this one.

tglase@tglase:~ $ bash -c 'IFS=; x=abc; printf "<%s>\n" ${x#$*}' x a b | sed -n l
<abc>$
tglase@tglase:~ $ dash -c 'IFS=; x=abc; printf "<%s>\n" ${x#$*}' x a b | sed -n l
<a>$
<abc>$
tglase@tglase:~ $ ksh93 -c 'IFS=; x=abc; printf "<%s>\n" ${x#$*}' x a b | sed -n l
<c>$
tglase@tglase:~ $ mksh -c 'IFS=; x=abc; printf "<%s>\n" ${x#$*}' x a b | sed -n l
<\a\300a>$
<abc>$
tglase@tglase:~ $ pdksh-5.2.14 -c 'IFS=; x=abc; printf "<%s>\n" ${x#$*}' x a b | sed -n l
<abc>$

Makes you wonder if ksh93 gets it right, or if bash/pdksh do.
But I agree that mksh’s output is just as broken as dash’s here.

> POSIX requires word splitting be performed upon arithmetic
> expansion.  Yes, that's stupid, even more stupid than the way
> $*/$@ are handled in ksh, but that's the way it is.
[…]
> But not mksh (and I'd praise it for doing the right thing here).
>
> $ mksh -c 'IFS=2; echo $((11*11))'
> 121

I’d praise it too, except, your mksh is too old. I was notified
of this POSIX requirement being unearthed, and changed the shell
to comply. (The requirement to parse $((010)) as 8 is worse IMO,
and only done if “set -o posix”.)

tglase@tglase:~ $ mksh -c 'IFS=2; echo $((11*11))'
1 1
tglase@tglase:~ $ mksh -c 'print $KSH_VERSION'
@(#)MIRBSD KSH R50 2014/10/07

Bugfixes to the shell to adhere more strictly to POSIX are frequent.
But this should have been in R50 already.

bye,
//mirabilos
-- 
Sometimes they [people] care too much: pretty printers [and syntax highligh-
ting, d.A.] mechanically produce pretty output that accentuates irrelevant
detail in the program, which is as sensible as putting all the prepositions
in English text in bold font.	-- Rob Pike in "Notes on Programming in C"


Reply to: