Bourne shell的 - 使在一个阵列的每个元素的循环? [英] Bourne shell - make a loop for each element in an array?
问题描述
这是我的数组:
ListTabs =
ListTabs = $ ListTabsT_Tab1 \\ n
ListTabs = $ ListTabsT_Tab2 \\ n
ListTabs = $ ListTabsT_Tab3
回声$ ListTabs
arrArr = 0
OLD_IFS = $ IFS;
IFS = \\ n
为listArr在$ {ListTabs [@]};
做
#echo $ listArr
MYDIR [$ {} ARR] = $ listArr
((arrIdx = $ ARR + 1))
DONE
IFS = $ OLD_IFS;
然后,我已经照这样做一个排序的ID从选择(FILESELECT_DAT是查询的输出文件):
排序-u $ {FILESELECT_DAT}> $ {} SORT_OUT1
ok..Now我必须做出一个循环,对数组的每个元素使得选取的$ ID =值{} SORT_OUT1。因此,有2个循环。过了一会的ID和一个for循环的选择。如何能i循环$ {} SORT_OUT1里面的ID?我觉得这是开始
ID =
而读的$ id
做
在$ {ListTabs} listArr
做
-
-
SELECT * FROM $ ListTabs(但结果常是在每个循环中的第一个选项卡)
WHERE ID = $ {ID}(但他告诉我所有ID)
-
-
完成< $ {} SORT_OUT1
任何想法?谢谢
listArr =(T_Tab {1,2,3})
排序-u$ FILESELECT_DAT> $ SORT_OUT1
同时读取ID;做
在$ {listArr [@]}ListTabs;做
...
DONE
完成< $ SORT_OUT1
要仔细的身体没什么<$ C $ C>为 -loop从标准输入读取,否则会消耗用于对输入的一部分读
命令。为了安全起见,使用一个单独的文件描述:
同时读取-u 3 ID;做
...
做3'; $ SORT_OUT1
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
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"
这篇关于Bourne shell的 - 使在一个阵列的每个元素的循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!