Thread: ksh arrays
View Single Post
  #1   (View Single Post)  
Old 6th May 2008
mtx's Avatar
mtx mtx is offline
Real Name: Valentin Bud
Fdisk Soldier
 
Join Date: May 2008
Location: RO/TM
Posts: 79
Default ksh arrays

i have started to use (better said learn) ksh as a scripting language about a week ago. as i was reading "Learning the Korn Shell (2nd edition)" i have reached at some point the array part.
so i have tried to make the following simple script.
Code:
# cat array.sh
#!/usr/local/bin/ksh93

K=~/bin

cd $K
KA=$(ls $PRE.*)
print ${#KA[*]}
running the script yields the following output
Code:
# ./array.sh
1
As far as i have read in the book this should print the total number of array components.
Using the -x feature of ksh i have the following output:
Code:
# ksh93 -x array.sh
+ ls addvpn.sh disk.size.sh ksh.sh s.test.sh array.sh vpn.sh
+ KA=$'addvpn.sh\ndisk.size.sh\nksh.sh\ns.test.sh\nssh.connect.sh\nvpn.sh'
+ print 1
Trying to print an element from the array let's say the first
Code:
...
print ${KA[1]}
doesn't work either. The out put is blank.
Code:
# ksh93 -x array.sh
+ ls addvpn.sh disk.size.sh ksh.sh s.test.sh ssh.connect.sh vpn.sh
+ KA=$'addvpn.sh\ndisk.size.sh\nksh.sh\ns.test.sh\nssh.connect.sh\nvpn.sh'
+ print ''
what am i missing here? thanks

all the best,
v
__________________
Stop! think! ... the problem is somewhere between the monitor and chair...
"First they ignore you, then they laugh at you, then they fight you, then you win." Gandhi
links: spreadbsd syk
Reply With Quote