Skip to main content
added 1 character in body
Kingofkech
  • 1.1k
  • 2
  • 12
  • 26

I have a problem when using curl on my linux script:

 #!/bin/bash userName="user"; passWord="password"; tenantName="tenant"; commande="curl -X POST -H \"Content-Type: application/json\" -H \"Cache-Control: no-cache\" -H \"Postman-Token: 111131da-8254-21b3-1b95-9c12954152c9\" -d '{\"auth\":{\"tenantName\":\"$tenantName\",\"passwordCredentials\": {\"username\":\"$userName\",\"password\":\"$passWord\"}}}' \"http://controller:5000/v2.0/tokens\"" 

When the output of the variable commande is copy pasted into the shell it works, but when i use :

 res= $(eval $commande) #or res=`$commande` 

Neither one of those commands works, and this is the output error i usually get:

 line 11: {"access":: command not found 

PS: If i do

 echo $comande$commande

And then i copy past the result on the shell it works,If anyone can help me that would be great !

I have a problem when using curl on my linux script:

 #!/bin/bash userName="user"; passWord="password"; tenantName="tenant"; commande="curl -X POST -H \"Content-Type: application/json\" -H \"Cache-Control: no-cache\" -H \"Postman-Token: 111131da-8254-21b3-1b95-9c12954152c9\" -d '{\"auth\":{\"tenantName\":\"$tenantName\",\"passwordCredentials\": {\"username\":\"$userName\",\"password\":\"$passWord\"}}}' \"http://controller:5000/v2.0/tokens\"" 

When the output of the variable commande is copy pasted into the shell it works, but when i use :

 res= $(eval $commande) #or res=`$commande` 

Neither one of those commands works, and this is the output error i usually get:

 line 11: {"access":: command not found 

PS: If i do

 echo $comande

And then i copy past the result on the shell it works,If anyone can help me that would be great !

I have a problem when using curl on my linux script:

 #!/bin/bash userName="user"; passWord="password"; tenantName="tenant"; commande="curl -X POST -H \"Content-Type: application/json\" -H \"Cache-Control: no-cache\" -H \"Postman-Token: 111131da-8254-21b3-1b95-9c12954152c9\" -d '{\"auth\":{\"tenantName\":\"$tenantName\",\"passwordCredentials\": {\"username\":\"$userName\",\"password\":\"$passWord\"}}}' \"http://controller:5000/v2.0/tokens\"" 

When the output of the variable commande is copy pasted into the shell it works, but when i use :

 res= $(eval $commande) #or res=`$commande` 

Neither one of those commands works, and this is the output error i usually get:

 line 11: {"access":: command not found 

PS: If i do

 echo $commande

And then i copy past the result on the shell it works,If anyone can help me that would be great !

edited tags
Link
ilkkachu
  • 145.9k
  • 16
  • 260
  • 431
Kingofkech
  • 1.1k
  • 2
  • 12
  • 26

Using a variable to execute a curl command

I have a problem when using curl on my linux script:

 #!/bin/bash userName="user"; passWord="password"; tenantName="tenant"; commande="curl -X POST -H \"Content-Type: application/json\" -H \"Cache-Control: no-cache\" -H \"Postman-Token: 111131da-8254-21b3-1b95-9c12954152c9\" -d '{\"auth\":{\"tenantName\":\"$tenantName\",\"passwordCredentials\": {\"username\":\"$userName\",\"password\":\"$passWord\"}}}' \"http://controller:5000/v2.0/tokens\"" 

When the output of the variable commande is copy pasted into the shell it works, but when i use :

 res= $(eval $commande) #or res=`$commande` 

Neither one of those commands works, and this is the output error i usually get:

 line 11: {"access":: command not found 

PS: If i do

 echo $comande 

And then i copy past the result on the shell it works,If anyone can help me that would be great !

close