Search code examples
bashgnu-parallel

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?


Solution

  • 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)