0

I am not even sure if this is possible or not. I am trying to create a loop where i can curl with different values from a file.

for i in `cat id`;
do curl -X POST 'https:/myurl \
--header 'X-XX-Authorization: XX' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'ACS-Licensing-Ack: XXXX' \
--header 'Authorization: Bearer XXXXX' \
--data-urlencode 'XXID=`find * -name $i`'
done

I get a response

{"code":"400-bad-request","message":"XX app with ID `find * -name $i` not found"}

How do i put in the value from $i that i captured earlier into this --data-urlencode field? My id file is very simple, it contains a few numbers like below. 1234 23232 32323 any help is highly appreciated. Thanks.

This is my id file. It is basically a list of numbers

1761
1762
1763
1764
1765

So my ultimate aim is to go in a loop where the first curl request will go --data-urlencode 'XXID=1761' second request will go --data-urlencode 'XXID=1762', third goes --data-urlencode 'XXID=1763' etc

1 Answer 1

3

You cannot use single quotes ' for variables as anything between them will be treated as literal text and not be expanded by the shell. Instead use double quotes ".

Also find is an utility to search files, not in files.

The following should work:

#!/bin/bash

for line in $(cat ./id)
do
        curl -X POST 'https:/myurla \
        --header 'X-XX-Authorization: XX' \
        --header 'Content-Type: application/x-www-form-urlencoded' \
        --header 'ACS-Licensing-Ack: XXXX' \
        --header 'Authorization: Bearer XXXXX' \
        --data-urlencode XXID="$line"
done

If your id file only contains a number which is increasing by 1 every line, you could use a seq of {..} to create a sequence of numbers:

for num in {1761..1765}
do
        echo $num
done
for num in $(seq 1761 1765)
do
        echo $num
done
6
  • Actually i tried that combination as well. when i do that like you requested i get the below {"code":"400-bad-request","message":"XXID must be sent in the request body"} Mar 18, 2022 at 14:30
  • You want the content of the file to be XXID or the name of the file? Mar 18, 2022 at 14:32
  • I want the content of the file to be the value of xxid. The content of the file is 1741, 1742 etc. So it should loop as --data-urlencode "XXID=1741", --data-urlencode "XXID=1742" etc Mar 18, 2022 at 14:35
  • Well, that cant work like that. find is for finding files, not file contents. Please edit your question with example data from your id file. Mar 18, 2022 at 14:37
  • ok i edited this question. i am new to programming so apologise for the confusion. Mar 18, 2022 at 14:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .