Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何在脚本中使用外部变量文件_Bash_Gnu Parallel - Fatal编程技术网

Bash 如何在脚本中使用外部变量文件

Bash 如何在脚本中使用外部变量文件,bash,gnu-parallel,Bash,Gnu Parallel,是否可以从文件中读取变量并通过并行方式将其发送到bash脚本 例如: 我有一个名为data.txt的文件,其中包含以下内容: apple red banana yellow grape green 我想使用Parallel读取这个文件,并使用每一行作为变量运行bash脚本。 此脚本的结果必须是: Fruit: apple Color: red Fruit banana Color: yellow Fruit: grape Color: green 当然可以: 其中script是: #!/

是否可以从文件中读取变量并通过并行方式将其发送到bash脚本

例如:

我有一个名为data.txt的文件,其中包含以下内容:

apple red
banana yellow
grape green
我想使用Parallel读取这个文件,并使用每一行作为变量运行bash脚本。 此脚本的结果必须是:

Fruit: apple
Color: red

Fruit banana
Color: yellow

Fruit: grape
Color: green
当然可以:

其中
script
是:

#!/bin/bash
echo -e "Fruit: $1"
echo -e "Colour: $2"
根据您对事物的看法,您将使用稍微不同的语法获得相同的结果:

cat data.txt | parallel --colsep ' ' ./script {1} {2}

我的回答解决了你的问题吗?如果是这样,请考虑接受它作为您的答案-点击空心蜱/支票旁边的选票计数。如果没有,请说出什么不起作用,以便我或其他人可以进一步帮助您。谢谢
cat data.txt | parallel --colsep ' ' ./script {1} {2}