Array error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Array error
# 1  
Old 05-20-2009
Array error

Smilie Hi,

I am assigning value to array in for loop,
here is the code:

for arg in $FILE
do
TMP=`dirname $arg`
${DIR[i]}=$TMP
echo ${DIR[i]}
let "i = $i + 1"
done

Here TMP gives,
d1/data/BCR
d1/data/BLM


Getting following error:

temp.sh: =d1/data/BCR: No such file or directory
temp.sh: =d1/data/BLM: No such file or directory


Can anyone please advise...
# 2  
Old 05-20-2009
What is in the $FILE variable
ie., show the output of
Code:
echo "$FILE"

# 3  
Old 05-20-2009
This is not an assignment.
Code:
${DIR[i]}=$TMP

I believe this is what you intended to do:

Code:
DIR[i]=$TMP

# 4  
Old 05-20-2009
Thanks mate, its working...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multidimensional array:awk error

awk -F'\t' -v OFS='\t' ' { if($2 in arr) { #print "Sahi", NR,arr for(k=2;k<=NF;k++){ # sum]+=$2 } } else { arr=NR #print "awk",NR for (k=3;k<=NF ; k++){ sum=$k } } } (7 Replies)
Discussion started by: genome
7 Replies

2. Shell Programming and Scripting

error while updating rows in sql with values in array variable

Hi, I need to update rows in a table based on the values in an array variable. code is : while read line do error_msg="$(echo $line)" index=`expr $index+1` done <"logs/$ffile" rows_count=${#error_msg } i=0 while do echo "error msgs is... (2 Replies)
Discussion started by: RP09
2 Replies

3. Shell Programming and Scripting

awk output error while loop through array

Have built this script, the output is what I needed, but NR 6 is omitted. Why? Is it an error? I am using Gawk. '{nr=$2;f = $1} END{for (i=1;i<=f;i++) if (nr != i) print i, nr }' input1.csv >output1.csvinput1.csv 1 9 3 5 4 1 7 6 8 5 10 6 output1.csv > with the missing line number 6. 6 is... (5 Replies)
Discussion started by: sdf
5 Replies

4. Programming

C++ Segmentation error with bi-dimensional array

Hello, I'm experiencing a weird seg fault at run time when initializing a bi-dimensional array and initializing a class. Please see below code and comments describing the error and the instances when it occurs and when it does not occur. Compiled with g++ segf.cpp -o segf output On... (5 Replies)
Discussion started by: nmset
5 Replies

5. Programming

Error message: invalid types 'bool...' (array problem)

Hello everyone. I'm stuck with an error message that neither I nor any of my computer science peeps can understand. The program I wrote is meant to be a simple decimal to binary converter, but with this message it's more complicated than I thought. Here's the code: #include <iostream>... (2 Replies)
Discussion started by: qf_woodfox
2 Replies

6. UNIX for Dummies Questions & Answers

array error

hi all, when i use array like this: array=223 echo ${array} result is : array: 1,2: syntax error thanx. ---------- Post updated at 09:21 AM ---------- Previous update was at 09:20 AM ---------- sorry, i had written wrongly. when i use array like this: array=223 echo... (2 Replies)
Discussion started by: temhem
2 Replies

7. HP-UX

need your help for HP virtual array 7400 disk replacement error

hi all! I found a the state of disk at JA0/D13 was failed this morning. then i replaced it this afternoon,but i run #dsp -s the array status displayed ==================================== STATUS Subsystem State: 1 The Subsystem is TESTING. The array is REBUILDING and is 87%... (0 Replies)
Discussion started by: JoyOnLine
0 Replies

8. UNIX for Dummies Questions & Answers

Loop on array variable returning error: 0 not found

I'm guessing i have a syntax error. I'm not sure it get's past the the while condition. I get an error 0 not found. Simple loop not sure what I'm doing wrong. #!/usr/bin/ksh set -A MtPtArray /u03 /u06 tUbound=${#MtPtArray } echo $tUbound i=0 while ($i -lt $tUbound) do print... (4 Replies)
Discussion started by: KME
4 Replies

9. Shell Programming and Scripting

Perl Array Error when run - I think???

My code isn't pretty, my verbage isn't exact and I probably don't have all my facts together (story of my life). I know what I want with this script: to join three simple lines line 1,2,3 then repeat over and over again with 4,5,6 until the end of the file. the lines are the same, date,date,text.... (3 Replies)
Discussion started by: jseager
3 Replies

10. Shell Programming and Scripting

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. #!/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... (1 Reply)
Discussion started by: yoavbe
1 Replies
Login or Register to Ask a Question