所以我为此搜索了很多,我对Shell很新, 我想迭代SHELL脚本中的Resultset行,并且我希望使用当前行的每一列执行一些代码。 让我们假设结果集看起来像这样。
Query Priority Size
---------------------------------------------------
this is a sentence to execute high 124400
this is another example low 15000000
...
那么我如何设法迭代这个Resultset并将每一列存储到他自己的变量中呢?这是第一行的例子:
var1="this is a sentence to execute"
var2="high"
var3=124400
#repeat process for next line
答案 0 :(得分:0)
以下是您可以做的事情:
# using an array - works great if we have a variable number of columns
while IFS=, read -r -a row; do
# ${row[0]} => column1, ${row[1]} => column2 and so on
# process data
done < input.dat
# using variables - works great if we have a fixed set of variables
while IFS=, read -r column1 column2 column3; do
# process data
done < input.dat