Backticks in Bash script doesn't interpret curl parameter while command execution

96 Views Asked by At

I am executing the below command inside the shell script:

CURL_RESPONSE=`curl --request POST "$1" --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'grant_type="$4"' --data-urlencode 'scope=operator test' --data-urlencode 'client_id=$2' --data-urlencode 'client_secret=$3' -s

But when i am running the script, getting below error:

`curl Response is {"code":"400","description":"Invalid grant_type. Only client_testcred is accepted"}
`

I am passing client_testcred in $4 actually.

CURL_RESPONSE=`curl --request POST "$1" --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'grant_type="$4"' --data-urlencode 'scope=operator test' --data-urlencode 'client_id=$2' --data-urlencode 'client_secret=$3' -s

Even i tried below command using args, but doesn't work:

args=(--request POST "$1" --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'grant_type=client_credentials' --data-urlencode 'scope=operator supervisor' --data-urlencode 'client_id=$2' --data-urlencode 'client_secret=$3' -s) CURL_RESPONSE=curl "${args[@]}"``

I am expecting a token as output in CURL_RESPONSE.

1

There are 1 best solutions below

0
AVTUNEY On

You are not passing $4 correctly.

Try this:

CURL_RESPONSE=$(curl --request POST "$1" --header "Content-Type: application/x-www-form-urlencoded" --data-urlencode "grant_type=$4" --data-urlencode "scope=operator test" --data-urlencode "client_id=$2" --data-urlencode "client_secret=$3" -s)