问题原文
原帖链接 · user1700840 · CC BY-SA 3.0
I'm trying to run many instances of a script with GNU parallel, but the script takes no arguments.
If I just execute 'parallel foo.sh' I get this:
parallel: Warning: Input is read from the terminal. Only experts do this on purpose. Press CTRL-D to exit.
社区高分解答
原帖链接 · jwfearn · CC BY-SA 3.0
Assuming you want to run ten times, this syntax will work:
parallel -n0 foo.sh ::: {1..10}
parallel needs an input sequence of some length (::: {1..10}) AND you need to ignore the contents of the input sequence(-n0), you only care about its length.
Your original command: parallel foo.sh, contains no input sequence to indicate how much parallelism you want. The cryptic warning is telling you that parallel is going to start listening to the terminal for an input sequence, and that this is probably not what you want.
Here's the tutorial example:
seq 10 | parallel -n0 my_command my_args
How it works:
parallelalways takes an input sequence from somewhere. It can be an inline space-delimited sequence preceded by:::OR a newline-delimited sequence from a file or filelike source such as a pipe. In this example the input sequence is from a pipe.seq 10produces a newline-delimited sequence of digits from one to ten.- The
-n0option tells parallel to ignore the values in the input sequence. All we care about is the length of the sequence, not its contents. Even though the digits aren't used, the command will still execute ten times.
Another example:
parallel -n0 echo -n 'x' ::: {1..5}
How it works:
- Input sequence is inline.
{1..5}produces a space delimited sequence of digits from one to five.-n0ignores sequence values (and we echo the string'x'each time instead.)- Output:
xxxxx
Compare to:
parallel echo -n ::: {1..5}
How it works:
- Input sequence is inline.
{1..5}produces a space delimited sequence of digits from one to five.- Each value from the input sequence is used as an argument to
echo. Order not guaranteed. - Output:
43215. Could be any order.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
