Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to xargs for processing pipeline [duplicate]

Tags:

shell

unix

curl

I am trying to run a curl command which will need arguments coming in from a pipe

some operation | sort | head -n -2 | curl -s "blah/blah/<argument goes here>/blah"

i cant figure out how to pass each argument one at a time. One way that i found was

some operation | sort | head -n -2 | xargs -l "$" curl -s "blah/blah/$/blah"

but i get

xargs: $: No such file or directory

what does it mean? why is it trying to read $ as a file?

like image 349
AbtPst Avatar asked Dec 06 '25 07:12

AbtPst


1 Answers

See BashFAQ #1 for the best-practices way to read a string line-by-line:

#!/bin/bash
#      ^^^^ - not /bin/sh, or <() will be a syntax error

while IFS= read -r line; do
  curl -s "blah/blah/$line/blah"
done < <(some operation | sort | head -n -2)
like image 199
Charles Duffy Avatar answered Dec 08 '25 22:12

Charles Duffy