0

I am running a shell script where I am trying to set the output of the command to a variable but it fails to pass the value of the input variable to the command that gets executed.

#!/bin/bash

request='<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:execute xmlns:ns2="http://common.ravi.com/"><arg0><clientInfoString>data-api</clientInfoString><dsAccessPassPhrase>password</dsAccessPassPhrase><dsAccessUser>user</dsAccessUser><operation>getData</operation><operationArgTypes>com.ravi.SpotMarketKey</operationArgTypes><parameters><object>rO0ABXNyAC5jb20ucmJzLmdibS5yaXNrLmRhdGEubWFya2V0LlNwb3RNYXJrZXRLZXlJbXBsAAAAAAAAAAECAAFMAAxidXNpbmVzc0RhdGV0AB9MY29tL3Jicy9nYm0vcmlzay91dGlsL2RhdGUvRHQ7eHBzcgAoY29tLnJicy5nYm0ucmlzay51dGlsLmRhdGUuRHRVdGlsJER0SW1wbIdazKHBJGu5AgABSQAEZGF0ZXhwAB+THw==</object></parameters><requestId>0_0</requestId><serializationMethod>simple</serializationMethod><serviceName>com.ravi.DataProvider</serviceName></arg0></ns2:execute></soap:Body></soap:Envelope>'

echo $request

res=`curl -X POST -H 'Content-type: text/xml'  http://localhost:8080/data-services/services/DataService -d '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:execute xmlns:ns2="http://common.data.risk.gbm.rbs.com/"><arg0><clientInfoString>data-api-6.8.54-SNAPSHOT_LONMW53910</clientInfoString><dsAccessPassPhrase>tim3lord</dsAccessPassPhrase><dsAccessUser>DSUser</dsAccessUser><operation>getFXRateSet</operation><operationArgTypes>com.rbs.gbm.risk.data.market.SpotMarketKey</operationArgTypes><parameters><object>rO0ABXNyAC5jb20ucmJzLmdibS5yaXNrLmRhdGEubWFya2V0LlNwb3RNYXJrZXRLZXlJbXBsAAAAAAAAAAECAAFMAAxidXNpbmVzc0RhdGV0AB9MY29tL3Jicy9nYm0vcmlzay91dGlsL2RhdGUvRHQ7eHBzcgAoY29tLnJicy5nYm0ucmlzay51dGlsLmRhdGUuRHRVdGlsJER0SW1wbIdazKHBJGu5AgABSQAEZGF0ZXhwAB+THw==</object></parameters><requestId>0_0</requestId><serializationMethod>simple</serializationMethod><serviceName>com.rbs.gbm.risk.data.market.FrontOfficeT0DataProvider</serviceName></arg0></ns2:execute></soap:Body></soap:Envelope>'`

echo $res

#fails here
res1=`curl -X POST -H 'Content-type: text/xml'  http://localhost:8080/data-services/services/DataService -d '${request}'`

echo $res1

When I run the above script it correctly prints the value of res variable with value of the variable request resolved, but when the command is executed where it says "fails here", in that command the variable request is not resolved.

I have tried many options, calling it as below but no luck.

$(curl -X POST -H 'Content-type: text/xml'  http://localhost:8080/data-services/services/DataService -d '${request}')

Any help would be highly appreciated

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Ravi
  • 1,082
  • 4
  • 15
  • 24
  • Variables are not substituted in single quotes. Use double quotes. – glenn jackman May 26 '21 at 17:46
  • See: [Difference between single and double quotes in bash](http://stackoverflow.com/q/6697753/3776858) – Cyrus May 26 '21 at 17:49
  • Also, `\`...\`` is deprecated and has been for a while in `bash`. The correct syntax for a command substitution is **`"$(...)"`**. – CJK May 26 '21 at 17:52

0 Answers0