0

Trying to update data from a system using curl and url/token, but I am running into the following error. I believe the way I format the curl command in the shell script is incorrect but not sure how to fix it.

curl: (3) URL rejected: Malformed input to a URL function

When I run the curl command from terminal with the value, it is successful and the fields get updated.

curl -X 'PATCH' \
  'https://myurl/123' \

Ran the shell script below.

#!/bin/bash

while read line
do
line='${line%$cr}'

curl -X 'PATCH' \
  'https://myurl/${line}' \
  -H 'accept: */*' \
  -H 'Authorization: Bearer user:TOKEN' \
  -H 'Content-Type: application/json;odata.metadata=minimal;odata.streaming=true' \
  -d '[
  {
"path": "/field1",
"value": "10"
  },
  {
"path": "/field2",
"value": "200"
  }
]'

done < list.txt

list.txt contains

123

234

456

5
  • 'https://myurl/${line}' here line won't be replaced with the variable Commented Aug 5, 2024 at 15:59
  • 1
    This question is similar to: How to use an environment variable inside a quoted string in Bash. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Aug 5, 2024 at 16:00
  • I referenced this post - stackoverflow.com/a/8866817 Commented Aug 5, 2024 at 16:39
  • @0stone0 so should it be 'myurl/'${line}'' or 'myurl/"${line}"' ? Commented Aug 5, 2024 at 16:45
  • @0stone0 couldn't get it to work Commented Aug 5, 2024 at 17:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.