我使用下面的代码
tablelist=`SELECT tablename from List`
echo "table list is $tablelist"
结果显示为
table list is Table1
Table2
Table3
Table4
我想遍历结果。请建议我如何才能做到这一点。如果循环遍历当前表列表,它会在内循环中打印整个列表。
,$ {tablelist}";不是一行的结果。它是多行,每行一个条目。所以…最好不要把它当作一个简单的字符串。你应该把它当作一个文件。
#!/bin/bash
#tablelist=`SELECT tablename from List`
cat >tables.list <<"EnDoFiNpUt"
Table1
Table2
Table3
Table4
EnDoFiNpUt
i=1
#echo "${tablelist}" |
cat tables.list |
while read table
do
echo -e "t [${i}] TABLE: '${table}' ..."
echo -e "tt ... replace this line by some action using '${table}' ...n"
i=$((i+=1))
done
输出如下所示:
[1] TABLE: 'Table1'……
用'Table1'…[2] TABLE: 'Table2'……
用'Table2'…[3] TABLE: 'Table3'……
用'Table3'…[4] TABLE: 'Table4'……
用'Table4'…