nixCraft Linux / UNIX / Shell Scripting Forum

nixCraft

Linux / UNIX Tech Support Forum

Array limitation in Korn (ksh) shell?

This is a discussion on Array limitation in Korn (ksh) shell? within the Shell scripting forums, part of the Development/Scripting category; Hello I am using an array in one of my Korn Shell scripts. It works fine if I set the ...


Register free or login to your account to remove all advertisements.

Go Back   nixCraft Linux / UNIX / Shell Scripting Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

Thread Tools Display Modes
  #1 (permalink)  
Old 4th November 2008, 07:06 PM
dba dba is offline
Junior Member
 
Join Date: Nov 2008
OS: RedHat
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
dba is on a distinguished road
Default Array limitation in Korn (ksh) shell?

Hello

I am using an array in one of my Korn Shell scripts. It works fine if I set the name of Array in the script, but gives error if I try to set the name dynamically (eg by user input or read from some file).

For example, the below mentioned script works well

Code:
 #!/bin/ksh
 set -A ARR
while read line
do
 ARR[i]=${line}
 let i=${i}+1
done</tmp/d.dat
 
i=0
while [ ${i} -le ${#ARR[*]} ]
do
  echo ARR[i]
let i=${i}+1
done
But it gives error if I modify it as below:

Code:
#!/bin/ksh
echo "Enter Array Name"
read ARR
set -A $ARR
while read line
do
 $ARR[i]=${line}
 let i=${i}+1
done</tmp/d.dat
i=0
while [ ${i} -le ${#ARR[*]} ]
do
  echo ${$ARR[i]}
let i=${i}+1
done
The file /tmp/d.dat is a file containing some numbers line by line.
Can we make it to set the array name dynamically ?

Last edited by nixcraft; 12th November 2008 at 06:41 PM.
Reply With Quote
  #2 (permalink)  
Old 12th November 2008, 06:44 PM
nixcraft's Avatar
Never say die
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash, Perl, Python
Posts: 3,195
Thanks: 13
Thanked 394 Times in 292 Posts
Rep Power: 10
nixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond repute
Default

The value of all subscripts must be in the range of 0 through 1,048,575, so that is your range. I do not think so you can create dynamic array names in shell scripts.
__________________
Vivek Gite
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Do you run a Linux? Let's face it, you need help!
Cricket & IPL News Blog
Reply With Quote
Reply

Tags
ksh, ksh array, shell array, shell script, shell scripting


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Parse XML file and store data in array in shell scripting Nishanthhampali Shell scripting 7 2nd May 2010 02:26 PM
writing a shell script to find out my shell name jaymob123 Shell scripting 1 8th October 2007 12:36 AM


All times are GMT +5.5. The time now is 09:03 PM.


Powered by vBulletin® Version 3.8.6 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40