Populating array raised an error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Populating array raised an error
# 1  
Old 12-02-2008
Populating array raised an error

Hi,
The following test case populate an array named: array3.
Since array1 and array2 are equal in length and values array3 will remain empty.
Code:
#!/usr/bin/ksh
test() {
set -A array1 "A"
set -A array2 "A"
NUM_1=`echo ${#array1[*]}`
print "num elenemt in NUM_1 is ${NUM_1}"
i=1
for ELE2 in ${array2[*]}; do
                Z=0
        for ELE1 in ${array1[*]}; do
                if [[ $ELE1 != $ELE2 ]]; then
                        let Z=$Z+1
                        if [[ $Z = $NUM_1 ]]; then
                                ${array3[i]}=$ELE2
                                let i=i+1
                        fi
                fi
        done
done
print "The array 3 contain : ${array3[*]}"
NUM_2=`echo ${#array3[*]}`
exit 0
}
while :
   do
#  clear
  echo "----------------------------------------------"
  echo " * * * * * * * test * * * * *  * * "
  echo "----------------------------------------------"
  echo "[1] Test "
  echo "[2] Exit/stop"
  echo "----------------------------------------------"
  echo -n "Enter your menu choice [1-10]:"
  read yourch
  case $yourch in
    1) test ;;
    2) exit 10
       ;;
    *) echo "Opps!!! Please select choice 1,2"
       echo "Press a key. . ."
       ;;
  esac
done

Here are the results:
Code:
$ ./mytest.ksh
----------------------------------------------
 * * * * * * * test * * * * *  * * 
----------------------------------------------
[1] Test 
[2] Exit/stop
----------------------------------------------
Enter your menu choice [1-10]:1
num elenemt in NUM_1 is 1
The array 3 contain :

=====================================================

Now i took the same logic from this test and insreted it into another script.
This time i am getting an error regarding to array3.
I printed all the necessary information
Could you please tell me why i am getting an error in this case:

The relevant function is:

Code:
reset_initora_asm_diskgroups() {
print "Original DGs list: ${PreDistinctDGs[*]}"
print "Cloned   DGs list: ${AfterDistinctDGs[*]}"

print "Num of element in original DGs list:${num_of_unique_dgs_pre_clone}"
print "Num of element in Cloned   DGs list:${num_of_unique_dgs_after_clone}"
  j=1
  for ELE2 in ${AfterDistinctDGs[*]}; do
                Z=0
        for ELE1 in ${PreDistinctDGs[*]}; do
                if [[ $ELE1 != $ELE2 ]]; then
                        let Z=$Z+1
                        if [[ $Z = $num_of_unique_dgs_pre_clone ]]; then
                                ${array3[j]}=$ELE2
                                let j=j+1
                        fi
                fi
        done
  done
  print "j= ${j}"
  print "The array3 contain : ${array3[*]}"
  exit 0
}

Running the function raised the foollowing error:
Code:
Enter your menu choice [1-10]:6
Original DGs list: DSDWHDATA
Cloned   DGs list: DSDWHDATA
Num of element in original DGs list:1
Num of element in Cloned   DGs list:1
j= 1
./CloneASM.sh[478]: array3[*]: parameter not set

Thanks

Last edited by otheus; 12-05-2008 at 08:07 AM.. Reason: Added [code] tags
# 2  
Old 12-05-2008
This line is suspect:
[code]
${array3[i]}=$ELE2
[code]
array3 is not yet initialized, so its contents are empty, so it can't evaluate to any variable which $ would expand to. Maybe you mean:
Code:
array3[i]=$ELE2

Try that.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Populating a BASH array with a list of files including spaces-in-the-name

For the record, I already tried telling mgmt and the users to disallow spaces in filenames for this script, but it isn't happening for a number of ID10T-error-based reasons. I have simple list of 3 files in a directory that are named like this: bash-3.2$ ls -1 file* file1 file1 part2... (2 Replies)
Discussion started by: ckmehta
2 Replies

2. Programming

Populating Lists in Def using Python

Dipping around in python again and need to create a def that will populate a list(content) with the files that os.walk finds from within this directory and then I will re.search through each files looking for content. In learning Python, can someone point me in the right direction. This is what I... (3 Replies)
Discussion started by: metallica1973
3 Replies

3. Programming

populating a JList

Hi, I have to create a JList and the items I need to display are store in HashMap table. What would be the easiest way to populate this JList. Basically the items I want to display/show in the JList are the key values of the HashMap. Thanks in advance for any suggestions. (0 Replies)
Discussion started by: arizah
0 Replies

4. Shell Programming and Scripting

awk - Pre-populating an array from system command output

So, here's a scenario that requires the same logic as what I'm working on: Suppose that you have a directory containing files named after users. For awk's purposes, the filename is a single field-- something parse-friendly, like john_smith. Now, let's say that I'd like to populate an array in... (2 Replies)
Discussion started by: treesloth
2 Replies

5. Shell Programming and Scripting

Populating an Array

Guys, I need to iterate populate an array while going over files in directory. Can someone please tell me syntax I tried this but it isn't working ==> for F in `ls -p "${directory1}" | grep -v "\/"` do cd "${directory2}" cmp "${directory2}"/"${F}" "${directory1}"/"${F}" ... (2 Replies)
Discussion started by: Veenak15
2 Replies

6. Shell Programming and Scripting

populating array using awk

Hi. I have a file with the following structer: DB DISK LOCATION SIZE ============================================ PROD DATA_01 /dev/dm-23 10 PROD DATA_02 /dev/dm-24 10 PROD DATA_03 /dev/dm-25 10 DEV DATA_04 /dev/dm-26 10 DEV DATA_05 ... (1 Reply)
Discussion started by: yoavbe
1 Replies

7. Shell Programming and Scripting

Awk help with populating variable

Hi, I'm looking for help trying to parse a data stream. Any help would be greatly appreciated. My awk statement is awk '/Aug/{a=$2}/vol/{print a, host, $1, $2, $3, $4, $5}' out.txt Sample Data Stream "out.txt" ----------------------------- # Aug 3 00:00:00 2008 ===== DF =====... (3 Replies)
Discussion started by: jmd2004
3 Replies

8. Shell Programming and Scripting

automatically answer a question raised by a command

i have installed vmware on a text base linux node now i have to vmware-configure.pl to do the initial configuration now 1st step it askes for agreeing for a " License Agreement" for that i have to say "q" and "yes" to Accept it i want to run a script with does these 3 steps... (6 Replies)
Discussion started by: pbsrinivas
6 Replies

9. Programming

When is SIGCHLD is raised.

Hi, I have 2 processes X and Y. Y is exec() from X. In Y i have an exit handler, which is called when i return from main. With in exit handler i delete and object which in turn calls the destructor of the object, which terminates all the threads of Y. I believe that SIGCHLD is raised by Y as... (4 Replies)
Discussion started by: supersumanth
4 Replies
Login or Register to Ask a Question