diff --git a/check.t b/check.t index cd5500a..7f52d3e 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.300 2009/08/28 21:35:42 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.301 2009/08/28 22:46:19 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -25,7 +25,7 @@ # http://www.research.att.com/~gsf/public/ifs.sh expected-stdout: - @(#)MIRBSD KSH R39 2009/08/08 + @(#)MIRBSD KSH R39 2009/08/28 description: Check version of shell. stdin: @@ -4943,6 +4943,69 @@ expected-stdout: a b c d e f g a b c d e f --- +name: arrays-4 +description: + Check if Korn Shell arrays with specified indices work as expected +stdin: + v="c d" + set -A foo -- [1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b + echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|" +expected-stdout: + 5|a|$v|c d||$v|b| +--- +name: arrays-5 +description: + Check if bash-style arrays with specified indices work as expected +stdin: + v="c d" + foo=([1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b) + echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|" +expected-stdout: + 5|a|$v|c d||$v|b| +--- +name: arrays-6 +description: + Check if we can get the array keys (indices) for indexed arrays, + Korn shell style +stdin: + of() { + i=0 + for x in "$@"; do + echo -n "$((i++))<$x>" + done + echo + } + foo[1]=eins + set | grep '^foo' + echo = + foo[0]=zwei + foo[4]=drei + set | grep '^foo' + echo = + echo a $(of ${foo[*]}) = $(of ${bar[*]}) a + echo b $(of "${foo[*]}") = $(of "${bar[*]}") b + echo c $(of ${foo[@]}) = $(of ${bar[@]}) c + echo d $(of "${foo[@]}") = $(of "${bar[@]}") d + echo e $(of ${!foo[*]}) = $(of ${!bar[*]}) e + echo f $(of "${!foo[*]}") = $(of "${!bar[*]}") f + echo g $(of ${!foo[@]}) = $(of ${!bar[@]}) g + echo h $(of "${!foo[@]}") = $(of "${!bar[@]}") h +expected-stdout: + foo[1]=eins + = + foo[0]=zwei + foo[1]=eins + foo[4]=drei + = + a 0<zwei>1<eins>2<drei> = a + b 0<zwei eins drei> = 0<> b + c 0<zwei>1<eins>2<drei> = c + d 0<zwei>1<eins>2<drei> = d + e 0<0>1<1>2<4> = e + f 0<0 1 4> = 0<> f + g 0<0>1<1>2<4> = g + h 0<0>1<1>2<4> = h +--- name: varexpand-substr-1 description: Check if bash-style substring expansion works diff --git a/mksh.1 b/mksh.1 index 14c4b1c..758e4e2 100644 --- a/mksh.1 +++ b/mksh.1 @@ -1,4 +1,4 @@ -.\" $MirOS: src/bin/mksh/mksh.1,v 1.176 2009/08/28 21:51:52 tg Exp $ +.\" $MirOS: src/bin/mksh/mksh.1,v 1.177 2009/08/28 22:46:20 tg Exp $ .\" $OpenBSD: ksh.1,v 1.129 2009/05/28 06:09:06 jmc Exp $ .\"- .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 @@ -1260,6 +1260,11 @@ of the string value of parameter The number of elements in the array .Ar name . .Pp +.It Pf ${! Ns Ar name Ns [*]} +.It Pf ${! Ns Ar name Ns [@]} +The names of indices (keys) in the array +.Ar name . +.Pp .Sm off .It Xo .Pf ${ Ar name @@ -3472,6 +3477,20 @@ and also supported by .Nm ksh93 is: .Ic foo=(a b c) +.Pp +Another +.At +.Nm ksh93 +and +.Tn GNU +.Nm bash +extension allows specifying the indices used for +.Ar arg ... +.Pq from the above example, Ic a b c +like this: +.Ic set \-A foo \-\- [0]=a [1]=b [2]=c +or +.Ic foo=([0]=a [1]=b [2]=c) .It Fl a \*(Ba Ic allexport All new parameters are created with the export attribute. .It Fl b \*(Ba Ic notify diff --git a/sh.h b/sh.h index fda4367..b4feaf2 100644 --- a/sh.h +++ b/sh.h @@ -134,9 +134,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.333 2009/08/28 22:23:34 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.334 2009/08/28 22:46:21 tg Exp $"); #endif -#define MKSH_VERSION "R39 2009/08/08" +#define MKSH_VERSION "R39 2009/08/28" #ifndef MKSH_INCLUDES_ONLY