0

This is my array:

ListTabs=""
ListTabs=$ListTabs"T_Tab1\n"
ListTabs=$ListTabs"T_Tab2\n"
ListTabs=$ListTabs"T_Tab3"   
echo $ListTabs
arrArr=0
OLD_IFS=$IFS;
IFS=\n
for listArr in ${ListTabs[@]}; 
do 
     #echo $listArr
     MYDIR[${ARR}]=$listArr
     (( arrIdx = $ARR+ 1 ))
done
IFS=$OLD_IFS;

then, i have done a sort of id from a select in this way (FILESELECT_DAT is a output file of query):

sort -u ${FILESELECT_DAT} > ${SORT_OUT1}

ok..Now i have to make a loop that for each element of array makes a SELECT where ID = values of ${SORT_OUT1}. So there are 2 loops. A while on ID and a for loop for the select. How can i loop the ID inside ${SORT_OUT1}? I think this is the begin

id=""
while read $id
do
for ListTabs in ${listArr}
do 
-
-
SELECT * FROM $ListTabs(but the results is alway the first tab in each loop)
WHERE ID = ${id}(but he show me all IDs)
-
-
done < ${SORT_OUT1}

Any ideas? Thanks

1
  • 1
    ListTabs is not an array. It's a string. The entire first block of code can be replaced with listArr=( T_Tab{1,2,3} ). Commented May 15, 2013 at 13:37

1 Answer 1

2
listArr=( T_Tab{1,2,3} )
sort -u "$FILESELECT_DAT" > "$SORT_OUT1"
while read id; do
    for ListTabs in "${listArr[@]}"; do
     ...
    done
done < "$SORT_OUT1"

Take care that nothing in the body of the for-loop reads from standard input, or it will consume part of the input intended for the read command. To be safe, use a separate file descriptor:

while read -u 3 id; do
...
done 3< "$SORT_OUT1"
Sign up to request clarification or add additional context in comments.

3 Comments

It's a bourn shell so it's the only way i think to make an array. Your solution get an error.. Even in "done 3< "$SORT_OUT1". the output is : 3: This is not an identifier.
You tagged the question as bash, not sh.
Yes, you're right, sorry but i use both bash and sh and i confuse them. Howevery, is sh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.