Consider this simple bash script : (I am writing myurl
as a placeholder for the correct URL; and myhost
as the placeholder for the correct hostname for privacy here.)
for a in `seq 400 450`; do
curl --request POST \
--url myurl \
--header 'Content-Type: application/json' \
--header 'Host: myhost' \
--data '{
"devID": "21010010",
"count": 0,
"fileEnd": 1,
"line": "",
"file": "$a"
}'
done
This is rejected as bad request. I want, the output of seq
, (e.g. the number 410) to be a quote delimated string. Notice the line "file": "$a"
. If I write "file": "410"
, this works perfectly, and also for any other file between 400 and 450 - as long as it is surrounded by ""
quotes.
Question :
I want, that in each iteration of the loop, the curl request should include the number coming from the seq
command surrounded by ""
. So the first call should be :
curl --request POST \
--url myurl \
--header 'Content-Type: application/json' \
--header 'Host: myhost' \
--data '{
"devID": "21010010",
"count": 0,
"fileEnd": 1,
"line": "",
"file": "400"
}'
The next one to be :
curl --request POST \
--url myurl \
--header 'Content-Type: application/json' \
--header 'Host: myhost' \
--data '{
"devID": "21010010",
"count": 0,
"fileEnd": 1,
"line": "",
"file": "401"
}'
and so on.
How can I do this? Thank you.