首页 > 解决方案 > 如何在bash中将数字序列重定向到并行

问题描述

我想并行化 curl 请求,我在这里使用了代码。我要使用的输入是使用生成的数字序列,seq但重定向不断给我错误,例如不明确的输入。

这是代码:

#! /bin/bash

brx() {
  num="$1"
  curl -s "https://www.example.com/$num"
}
export -f brx

while true; do
  parallel -j10 brx < $(seq 1 100)
done

我尝试使用 < `seq 1 100` 但这也没有用。有谁知道我怎么能绕过这个?

标签: bashgnu-parallel

解决方案


对 OP 当前代码的小调整:

# as a pseduto file descriptor

parallel -j10 brx < <(seq 1 100)

或者:

# as a 'here' string

parallel -j10 brx <<< $(seq 1 100)

推荐阅读