compound variable in korn shell

in a text " Korn Shell Unix programming Manual 3� Edition"

i have found this sintax to declare a compoud variable:

variable=(
[datetype] fild1 [=value]
[datetype] fild1 [=value]
)

but this sintax in ksh and sh (HP-UNIX) not work...

why?? exist another solution for this type of variable ???

That syntax is correct. For ksh93 only.

try:

a="one.two"
echo $a
one.two
echo ${a%.*}
one
echo ${a#*.}
two

Compound Variables
The Korn shell also supports compound variables, which are similar to structures or records in other
languages, that is a meta-datatype which is a group of related values, each of which can have a different
data type. The syntax for declaring compund variables is:

compound_variable=(
[datatype] field1[=value]
. . .
[datatype] fieldn[=value]
)

For example, we can use a compound variable to manage employee information:
$ employee=(
typeset name=Allenby
integer id=1243
float salary=9000.50
)

The syntax to display the value of a compound variable field is:

${compound_variable.field}
Here we access the employee compound variable:
$ print $employee
( typeset -E salary=9000.5 name=Allenby typeset -i
id=1243 )
$ print ${employee.name}

in HP/ksh not work....

and this :

$ typeset -AE exchange_rate
$ exchange_rate["DM"]=1.7
$ exchange_rate["FF"]=.15
$ exchange_rate["AS"]=.04
To display a list of associative array subscripts:
${!variable[*]} or ${!variable[@]}

not work ???

You need ksh93 (not ksh88):

$ Version M-11/16/88i
$ typeset -AE exchange_rate
ksh: typeset: bad option(s)
$ /usr/dt/bin/dtksh
$ print ${.sh.version}
Version M-12/28/93
$ typeset -AE exchange_rate
$ exchange_rate[DM]=1.7
$ exchange_rate[FF]=.15
$ exchange_rate[AS]=.04
$ print ${exchange_rate[FF]}
0.15
$ print ${exchange_rate[@]}
1.7 0.15 0.04
$ print ${!exchange_rate[@]}
DM FF AS

OK. !!!
exist a more info or manual to see a difference from ksh ???

( i try sobstitute the declare in my shells but the shell return more error in other point !!!!)

i serach with emule "dtksh" but i not found result .....

HP's version of ksh (ksh88) does not support compound variables. You will have to do one of these:

  1. See if any of these downloads are for you:
    KornShell Software
  2. See if zsh will work for you:
    ZSH - THE Z SHELL