Linux / UNIX Tech Support Forum
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.
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
Thread Tools | Display Modes |
|
|||
|
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
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
Can we make it to set the array name dynamically ? Last edited by nixcraft; 12th November 2008 at 06:41 PM. |
|
||||
|
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 |
![]() |
|
|
| 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 | |
|
|
|
||||
| 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 |