0

I'm trying to use two variables in a curl command on my ksh program, but it doesn't work.

Example:

  1. Original URL

    curl -s --header "Content-Type:application/json" --header "Accept:application/json" -X POST --data-binary '{"username":"foo","password":"foo_pwd"}' URL site
    
  2. On my program

    user=foo
    pwd=foo_pwd
    curl -s --header "Content-Type:application/json" --header "Accept:application/json" -X POST --data-binary '{"username":"'"$user"'","password":"'"$pwd"'"}' URL site
    

I've tried also to escape double quote with backslash but it also doesn't work.

Loudone
  • 309
  • 1
  • 2
  • 10

1 Answers1

2

First examine your script

user=foo
pwd=foo_pwd
echo '{"username":"'"$user"'","password":"'"$pwd"'"}'

Then run

user=foo
pwd=foo_pwd
curl -s --header "Content-Type:application/json" --header "Accept:application/json" -X POST https://example.com --data-binary '{"username":"'"$user"'","password":"'"$pwd"'"}'
Ali Hallaji
  • 3,712
  • 2
  • 29
  • 36