Stephane Chazelas <stephane.chazelas <at> gmail.com> writes:

> 
> 2014-07-29 22:53:04 +0000, michael:
> > Stephane Chazelas <stephane.chazelas <at> gmail.com> writes:
> > 
> > > Note that it's only about the ${var[:][+-]literal} syntax.
> > 
> > And $(command substitutions)
> 

Here's a different thing, though related. Sorry about this, mirabilos, but I 
just installed mksh yesterday and I'm trying to get acquainted. 

Anyway, it seems mksh behaves strangely with regards to assignments and $*. 
Maybe it's just wrongheaded of me, but I don't typically weakquote 
expansions in assignments, because I don't really expect them to expand, so 
I'll take a page from Stephane's book and show you what surprised me:

a='space divded  argument                                                  
here'
IFS=\  ; set -- $a
IFS= ; q="$*" ; nq=$*
printf '<%s>\n' "$*" $* "$q" "$nq"
CMD
<spacedivdedargument
here>
<space>
<divded>
<argument
here>
<spacedivdedargument
here>
<space>

I discovered it because I was counting spaces in a string by saving the 
string's len, setting IFS to <space> ; setting its expansion to the 
positionals, and squeezing out the spaces by setting IFS to null and saving 
$* like s=$*. After that I could $((oldlen - ${#s})) for my count - but mksh 
was giving me backwards numbers.

It looks like it gets truncated up there - only saving the first field. Now 
I know that $* is spec'd to behave differently when quoted, but I always 
understood that to mean when explicitly expanded - which is not what I'm 
generally used to in an assignment context. In my experience the above 
sequence ends with [ "$q" = "$nq" ] as true.

Like I said, sorry if it's a nuisance, but I thought you might want to know, 
and if I am making a wrong assumption here I'd be happy to learn it anyway.

-mike


Reply via email to