more fun with $*

Bug #1381993 reported by Thorsten Glaser
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
mksh
Fix Released
High
Thorsten Glaser

Bug Description

From: Stephane Chazelas <email address hidden>

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

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
<c>$
tglase@tglase:~ $ ksh93 -c 'IFS=; x=abc; printf "<%s>\n" ${x#$*}' x a b | sed -n l
<c>$
tglase@tglase:~ $ lksh -c 'IFS=; x=abc; printf "<%s>\n" ${x#$*}' x a b | sed -n l
<\a\300a>$
<abc>$
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>$
tglase@tglase:~ $ mksh -o sh -c 'IFS=; x=abc; printf "<%s>\n" ${x#$*}' x a b | sed -n l
<a>$
<abc>$

>The dash versions I have access to give the expected output
>(same as your ksh93).

>bash and pdksh join the arguments with spaces. And there's
>nothing in POSIX that allows them to do that.

But:

>ksh93 has some other interesting bugs:

tglase@tglase:~ $ bash -c 'IFS="*"; a=abcd; printf "<%s>\n" "$*" ${a##"$*"}' sh '' c
<*c>
<abcd>
tglase@tglase:~ $ ./dash -c 'IFS="*"; a=abcd; printf "<%s>\n" "$*" ${a##"$*"}' sh '' c
<*c>
<abcd>
tglase@tglase:~ $ ksh93 -c 'IFS="*"; a=abcd; printf "<%s>\n" "$*" ${a##"$*"}' sh '' c
<*c>
<d>
tglase@tglase:~ $ lksh -c 'IFS="*"; a=abcd; printf "<%s>\n" "$*" ${a##"$*"}' sh '' c
<*c>
<abcd>
tglase@tglase:~ $ mksh -c 'IFS="*"; a=abcd; printf "<%s>\n" "$*" ${a##"$*"}' sh '' c
<*c>
<abcd>
tglase@tglase:~ $ pdksh-5.2.14 -c 'IFS="*"; a=abcd; printf "<%s>\n" "$*" ${a##"$*"}' sh '' c
<*c>
<abcd>

tl;dr: Fix the first and keep the second as-is.

>And they don't say how those "arrays" are to be cast to scalars
>when not in list context since they don't specify arrays in the
>first place.
>
>The non-list contexts include
>
>a=$*
>${a#$*}
>
>case x in
> $a) ...;;
> "$a") ...
>esac
>${a#"$*"} # beware quotes also serve to cancel globs there
>
>$(( $* ))
>...

Interesting use for the asn subst.

Changed in mksh:
importance: Undecided → Low
Revision history for this message
Thorsten Glaser (mirabilos) wrote :

Preliminary fix committed, plus some test coverage. This is a real problem, raising priority.

Fix needs to be extended; CVS HEAD needs to be tested better.

Changed in mksh:
assignee: nobody → Thorsten Glaser (mirabilos)
importance: Low → High
status: New → In Progress
Revision history for this message
Thorsten Glaser (mirabilos) wrote :

mksh R50e is out

Changed in mksh:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.