我有以下文件:
%cat temp.csv
2019 11 16
2019 11 17
2019 11 18
2019 11 19
2019 11 20
2019 11 21
2019 11 22
2019 11 23
2019 11 24
2019 11 25
2019 11 26
我想执行以下命令:
myvar1="foo"
myvar2="bar"
./test foo 2019 11 16 bar
./test foo 2019 11 17 bar
...
./test foo 2019 11 25 bar
./test foo 2019 11 26 bar
但我不知道如何轻松地合并环境变量和temp.csv的输出,以便稍后将所有内容作为参数传递给xargs:
cat temp.csv | xargs test $myvar1 -n 3 $myvar2
This does not work!
使用GNU xargs:
xargs -I {} echo ./test "$myvar1" {} "$myvar2" < temp.csv
输出:
/测试foo 2019 11 16 bar./test foo 2019 11 17 bar./test foo 2019 11 18 bar./test foo 2019 11 19 bar./test foo 2019 11 20 bar./test foo 2019 11 21 bar./test foo 2019 11 22 bar./test foo 2019 11 23 bar./test foo 2019 11 24 bar./test foo 2019 11 25 bar./test foo 2019 11 26 bar
如果一切正常,请删除echo
。