liammclennan
liammclennan

Reputation: 5368

Substituting lines of a text file into bash commands

I want to run a bash command once for each line of a text file.

If I do:

while read l; do 
  echo $l; 
done < myfile.txt

I get each line echoed.

But when I use my actual command:

while read l; do 
  curl -X POST http://somedomain -H "Content-Type: application/json" -d $l
done < myfile.txt

I get errors. I think it may have something to do with escaping characters in the text file, but nothing I have tried works. What is the proper way to run a curl expression once for each line of a text file?

Upvotes: 0

Views: 395

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798456

To use quotes.

foocmd ... "$l"

Upvotes: 3

Related Questions