xargs的输入涉及空间 [英] xargs input involving spaces

查看:788
本文介绍了xargs的输入涉及空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac上使用工作OSX和我使用bash作为我的壳。我有一个脚本,去的东西的效果:

I am working on a Mac using OSX and I'm using bash as my shell. I have a script that goes something to the effect of:

VAR1="pass me into parallel please!"
VAR2="oh me too, and there's actually a lot of us, but its best we stay here too"
printf "%s\n" {0..249} | xargs -0 -P 8 -n 1 . ./parallel.sh

我得到的错误: xargs的:。:权限被拒绝。其目的是要并行运行(称为parallel.sh)一个又一个脚本,让美联储的数字0-249。此外,我想确保平行可以看到和我们VAR1和VAR2。但是,当我尝试用源脚本平行。 ./parallel ,xargs的不喜欢。采购的一点是因为剧本有其他变量我希望平行于访问。

I get the error: xargs: .: Permission denied. The purpose is to run a another script in parallel (called parallel.sh) which get's fed the numbers 0-249. Additionally I want to make sure that parallel can see and us VAR1 and VAR2. But when I try to source the script parallel with . ./parallel, xargs doesn't like that. The point of sourcing is because the script has other variables I wish parallel to have access to.

我已经读一些有关使用print0,因为xargs的分离是用空格的投入,但我真的不明白-print0并知道如何使用它。感谢你们可以提供任何帮助。

I have read something about using print0 since xargs separates it's inputs by spaces, but I really didn't understand what -print0 does and how to use it. Thanks for any help you guys can offer.

推荐答案

如果你想运行脚本的几个过程,那么他们不可能是父进程的一部分,因此它们不能访问相同的变量。但是,如果您导出变量,那么每个进程都可以得到他们的副本:

If you want the several processes running the script, then they can't be part of the parent process and therefore they can't access the exact same variables. However, if you export your variables, then each process can get a copy of them:

export VAR1="pass me into parallel please!"
export VAR2="oh me too, and there's actually a lot of us, but its best we stay here too"
printf "%s\n" {0..249} | xargs -P 8 -n 1 ./parallel.sh

现在你能把多余的点,因为你没有采购的parallel.sh脚本,你只是运行它。

Now you can just drop the extra dot since you aren't sourcing the parallel.sh script, you are just running it.

也没有必要使用 -0 因为你的投入仅仅是在每行的一系列数字,之一。

Also there is no need to use -0 since your input is just a series of numbers, one on each line.

这篇关于xargs的输入涉及空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆