0

I am trying to get some data as below. The problem I face is that if I run the curl command in shell as it is below, this works perfect, however if I run the

Works

curl -u blauser:blapsss "https://example.com" -d'[{ "name": "bla", "newname": "blagain"}]'

Does not work in script

getdata() {
url=$1
curl -u blauser:blapass $url
}



myurl="http://mynewurl/something" -d'[{ "name": "bla", "newname": "blagain"}]'"
getdata "$myurl"

Of course I did try to escape the quotes, square brackets etc. The problem I feel is somewhere around the place where I set the variable myurl="http://mynewurl/something" -d'[{ "name": "bla", "newname": "blagain"}]'"

The error I get is curl bad range specification in url position xx

Vaishnav
  • 611
  • 1
  • 9
  • 23
  • Your sentence seems to have been cut off after "however if I run the" – Barmar Sep 23 '21 at 07:14
  • 1
    Put "$url"` in quotes. – Barmar Sep 23 '21 at 07:14
  • 1
    Apart from that, the line where you assign to `myurl` is incorrect. You're trying to run `-d'[{ "name": "bla", "newname": "blagain"}]'"` as a *command*, with `myurl="http://mynewurl/something"` in its environment. Or actually, there's a stray double quote at the end of the line. Use an array instead: `myurl=("http://mynewurl/something" -d '[{ "name": "bla", "newname": "blagain"}]')`, and then `getdata "${myurl[@]}"`, and `url=("$@"); curl -u blauser:blapass "${url[@]}"` in the function. – Benjamin W. Sep 23 '21 at 08:31
  • Thanks @BenjaminW. I will try that and update you – Vaishnav Sep 23 '21 at 12:47
  • @BenjaminW. This is what I am trying exactly url="${base_url}/123254dfg344fqe3423/refs?api-version=5.0 -X POST -H \"Content-Type: application/json\" -d '\[{ \"name\": \"refs/heads/$branch\", \"oldObjectId\": \"$objectid\", \"newObjectId\": \"0000000000000000000000000000000000000000\"}\]'" NEXT LINE curl -sS -u blauser:blapssd "$url" – Vaishnav Sep 23 '21 at 18:58

0 Answers0