3

I wanted to parallelize curl requests and i used the code here. The input i want to use is a sequence of numbers generated using seq but the redirection keeps giving me errors like ambiguous input.

Here is the code:

#! /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

I tried with < `seq 1 100` but that didn't work either. Anyone know how i could get around this one?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
kenjoe41
  • 280
  • 2
  • 8

2 Answers2

5

Small tweak to OP's current code:

# as a pseduto file descriptor

parallel -j10 brx < <(seq 1 100)

Alternatively:

# as a 'here' string

parallel -j10 brx <<< $(seq 1 100)
markp-fuso
  • 28,790
  • 4
  • 16
  • 36
  • 1
    This is better than my answer - it is nearer to OP's attempt and also can provide an unlimited number of values on `stdin` whereas mine is limited by length of ARGMAX. – Mark Setchell Aug 31 '21 at 20:37
1

Try with bash brace expansion:

parallel echo ::: {1..100}

Or:

parallel echo ::: $(seq 1 100)
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432