【发布时间】:2017-12-17 06:11:23
【问题描述】:
我有一个脚本可以让我得到我想要的结果。我想提高脚本的性能。
我的脚本从文件 file1.txt 中获取参数。
内容如下:
table1
table2
table3
and so on
现在,当我使用下面的 while 语句时,脚本会按顺序运行。
while 声明如下:
while IFS=',' read -r a; do import.sh "$a"; done < file1.txt
现在,当我在 bash 中使用 xargs max-procs 实用程序时,脚本会根据 max-procs 的数量并行运行。
xargs 声明如下:
xargs --max-procs 10 -n 1 sh import.sh < file1.txt
现在我有另一个脚本
此脚本从文件 file2.txt 获取参数。
内容如下:
table1,db1
table2,db2
table3,db3
and so on
当我使用while 语句时,脚本运行良好。
while IFS=',' read -r a b; do test.sh "$a" "$b"; done < file2.txt
但是当我使用 xargs 语句时,脚本会给我 usage 错误。
xargs 声明如下。
xargs --max-procs 10 -n 1 sh test.sh < file2.txt
error 声明如下:
Usage : test.sh input_file
为什么会这样?
我该如何解决这个问题?
【问题讨论】:
-
您可以通过在命令中添加
echo轻松调试此问题:xargs --max-procs 10 -n 1 echo sh test.sh < file2.txt
标签: linux bash while-loop xargs