Operating System - Linux
1751836 Members
5216 Online
108782 Solutions
New Discussion юеВ

ksh oddity - already known?

 
SOLVED
Go to solution
David G Ledger
Occasional Advisor

ksh oddity - already known?

Needing to get the contents of a ksh array into an awk environment, I was tying to generate a single ksh var that could be embedded into in-line awk.

In a spare shell, try:
$ set -A x a b c d
$ set | grep '^x\['
x[0]=a
x[1]=b
x[2]=c
x[3]=d
$ set | awk '/^x\[/ { print }'
x[0]=a
x[1]=b
x[2]=c
x[3]=d
4$ set | awk -F= '/^x\[/ { $2 = "\"" $2 "\""; print $1 "=" $2}'
x[0]="a"
x[1]="b"
x[2]="c"
x[3]="d"
$ y="$(set | awk -F= '/^x\[/ { $2 = "\"" $2 "\""; print $1 "=" $2}')"
$ echo "$y"
x[0]="a"
x[1]="b"
x[2]="c"
x[3]="d"
$ set | grep '^x\['
x[0]=a
x[1]=b
x[2]=c
x[3]=d
x[1]="b"
x[2]="c"
x[3]="d"

Unsetting does not remove the 'extra' values. It's not '"' specific; try it with text chars.

This may be known already, but I havn't heard of it.

$Revision: @(#) all CUP11.11_BL2002_1129_1 PATCH_11.11 PHCO_27019
Fri Nov 29 08:52:39 PST 2002 $
$ B.11.11_LR Feb 8 2002 01:58:34 $
Version 11/16/88

David
5 REPLIES 5
Robert-Jan Goossens_1
Honored Contributor

Re: ksh oddity - already known?

David,

Try installing the latest ksh patch PHCO_33169

http://www4.itrc.hp.com/service/patch/patchDetail.do?patchid=PHCO_33169&sel={hpux:11.11,}&BC=main|search|

Regards,
Robert-Jan
David G Ledger
Occasional Advisor

Re: ksh oddity - already known?

Thanks Robert-Jan

Downloaded patch and installed.

Now at
$ B.11.11_LR Nov 4 2004 06:32:21 $
Version 11/16/88
but it still happens.

Seem to have some problems with -o vi mode command line edits now as well.

David
Peter Nikitka
Honored Contributor
Solution

Re: ksh oddity - already known?

Hi David,

there is nothing wrong with ksh.
Your grep just gets the data of the value of variable $y as well:
print "$y"
x[0]="a"
x[1]="b"
x[2]="c"
x[3]="d"
To get all array elements of x, enter
print "${x[*]}"
a
b
c
d

You may even get more lines of output in setting
set yy='
x[0]="more"'


mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
David Ledger at Bham
Occasional Advisor

Re: ksh oddity - already known?

Smacks forehead ...

Of course.

Thanks,
David
David G Ledger
Occasional Advisor

Re: ksh oddity - already known?

No problem - a case of wood and trees.