如何在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` 但这也不起作用。有谁知道我怎么能解决这个问题?
回答
对 OP 当前代码的小调整:
# as a pseduto file descriptor
parallel -j10 brx < <(seq 1 100)
或者:
# as a 'here' string
parallel -j10 brx <<< $(seq 1 100)