Tate
Tate

Reputation: 53

How to use variable in curl command in Linux bash shell script to send post request with file?

eg. I can execute below command in terminal successfully:

curl -sX POST -F 'file=@/tmp/test.tgz' -F 'fileName=test.tgz' http://localhost:8080/upload

However, if I replace the file path str "/tmp/test.tgz" with a variable in a bash shell script, then it wouldn't work, could you please help to tell me how to resolve it?

curl -sX POST -F 'file=@$myfile' -F 'fileName=test.tgz' http://localhost:8080/upload

Upvotes: 0

Views: 2263

Answers (2)

Stanal Wellia
Stanal Wellia

Reputation: 1

ff="'file=$myfile'"
fname="'fileName=test.tgz'"
eval curl -sX POST -F $ff $fname http://localhost:8080/upload

Upvotes: 0

Vadim Ponomarev
Vadim Ponomarev

Reputation: 96

Use " instead of ' if you want variable expansion

Upvotes: 1

Related Questions