I am trying to loop through the cells in a column in a csv file and assign each cell as a variable. I then want to take that variable and put it in a URL so it puts the cell from the csv in the url. When I run the script, it gives the error: "curl: (3) Illegal characters found in URL"
#!/bin/bash
IFS=,
cat /Users/User/Desktop/hardwares_2018-01-23_11-02-05.csv | while read id
temp=`echo $id | sed 's/"//g'`
#echo $temp
do
curl -H "X-Application-Authorization: Bearer Token" -H 'Accept: application/vnd.application.v2.1+xml' -X DELETE https://api.application.com/hardwares/${temp}.xml
done
My csv file looks like this
1945603
1945604
1945605
1945606
1945607
1945608
1945609
1945610
1945611
1945612
Any ideas?
Thanks
我认为您想要在“同时读取ID”部分之后的“执行”指令,而不是现在的位置。
I believe the problem is in the first headr -H
flag. It has white space in the string which might be getting interpreted as another argument to curl
.
Here I made some generic modification to the script. I don't have an environment to test it. Hope it helps.
$ cat test.sh
#!/bin/bash
h1flag="'X-Application-Authorization: Bearer Token'"
h2flag="'Accept: application/vnd.application.v2.1+xml'"
reqflag="DELETE"
baseurl="https://api.application.com/hardwares"
while read -r id
do
curl --verbose -H "${h1flag}" -H "${h2flag}" -X "${reqflag}" "${baseurl}/$id"
done < input.csv
An example line from above would look like the following,
$ curl --verbose \
-H 'X-Application-Authorization: Bearer Token' \
-H 'Accept: application/vnd.application.v2.1+xml' \
-X DELETE https://api.application.com/hardwares/1945603
I would suggest to use this on the cmdline
first before running it using the script.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.