蜂巢和数据库之间的完整性检查

时间:2013-09-17 13:32:22

标签: mysql bash for-loop hive

目前我有一个bash脚本,它对hive表执行基本行计数(将结果存储在变量中),然后将另一行计数到mysql表。 Bash然后评估2个变量。到目前为止没有任何问题。

还有另一个java.sh列出了大约50个表名 例如。 target_tables =“name_table1
name_table2
name_table3
......等等。

我想这需要一个for循环来自动运行上面的脚本来运行单个命令中的所有50个表?如何告诉我的脚本从anotherScript.sh中选择表名?

1 个答案:

答案 0 :(得分:1)

要遍历变量,您可以:

for table in $target_tables; do
    (do something with $table)
done

如果您的表名称包含空格,请使用IFS=$'\n'

(
    IFS=$'\n'
    for table in $target_tables; do
        (do something with $table)
    done
)

如果你使用bash 4.0+,最安全的是:

readarray -t tables <<< "$target_tables"
for table in "${tables[@]}"; do
    (do something with $table)
done
相关问题