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

$*/$@/$IFS and Bourne vs Almquist vs Korn vs mksh (Was: bash exorcism experiment ('bug' 762923 & 763012))

2014-10-15 12:13:06 +0200, Thorsten Glaser:
> On Mon, 13 Oct 2014, Stephane Chazelas wrote:
> > $*, $@, "$*" were not special in any way. They just underwent
> > the same rules as other variables. Only "$@" was.
> This changed in POSIX sh though. I remember having
> to change some things in mksh to adhere to 2008 and
> post-2008.

The POSIX spec is very unclear if not misleading.

"Expands to the positional parameters, starting from one"
doesn't make sense in most contexts.

I seem to recall it's been discussed some time ago on the austin
group ML, but unfortunately can't seem to recall anything else
about it.

BTW, it looks like there's a bug in mksh:

$ mksh -c 'IFS=; x=abc; printf "<%s>\n" ${x#$*}' x a b | sed -n l
$ mksh -c 'echo "$KSH_VERSION"'
@(#)MIRBSD KSH R50 2014/10/03

(pdksh 5.2.13 doesn't seem to be affected).

While we're at comparing ash and mksh.

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.

dash is compliant in that case

$ dash -c 'IFS=2; echo $((11*11))'
1 1

But not mksh (and I'd praise it for doing the right thing here).

$ mksh -c 'IFS=2; echo $((11*11))'

nor zsh in sh emulation.

I won't blame you if you don't change mksh so as to be
compliant so long as you don't blame dash for "IFS=; $@" to
expand to one word only ;-)


Reply to: