kenjoe41
kenjoe41

Reputation: 260

How to redirect sequence of numbers to parallel in bash

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?

Upvotes: 3

Views: 302

Answers (2)

markp-fuso
markp-fuso

Reputation: 34584

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)

Upvotes: 5

Mark Setchell
Mark Setchell

Reputation: 207540

Try with bash brace expansion:

parallel echo ::: {1..100}

Or:

parallel echo ::: $(seq 1 100)

Upvotes: 1

Related Questions