【问题标题】:How to redirect sequence of numbers to parallel in bash如何在bash中将数字序列重定向到并行
【发布时间】:2021-10-30 09:15:13
【问题描述】:

我想并行化 curl 请求,我使用了代码 here。 我要使用的输入是使用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 | parallel -j10 brx
  • @markp-fuso 这比我的回答好 - 你应该添加它并获得我的投票。

标签: bash gnu-parallel


【解决方案1】:

尝试使用 bash 大括号扩展

parallel echo ::: {1..100}

或者:

parallel echo ::: $(seq 1 100)

【讨论】:

    【解决方案2】:

    对 OP 当前代码的小调整:

    # as a pseduto file descriptor
    
    parallel -j10 brx < <(seq 1 100)
    

    或者:

    # as a 'here' string
    
    parallel -j10 brx <<< $(seq 1 100)
    

    【讨论】:

    • 这比我的回答要好 - 它更接近 OP 的尝试,并且还可以在 stdin 上提供无限数量的值,而我的受 ARGMAX 长度的限制。
    猜你喜欢
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多