Trying to pass a JSON object from one shell script to another.

If I send a JSON object with one value it works with the following: objectStorageCupsConfigData='{\"containerName\":""\"$objectStorageContainerDev\"}'

But if I add another value to the JSON object I get it in the wrong format: objectStorageCupsConfigData=''{\"containerName\":""\"$objectStorageContainerDev\",\"number2\":""}'' objectStorageCupsConfigData='{\"containerName\":""\"$objectStorageContainerDev\",\"number2\":""}'

First shell script does this


createCUPS "aa-contact-bags-objectStorage-config" "$objectStorageCupsConfigData"

The script with the function:

function createCUPS() {

set +e
cf service $serviceName

echo $serviceData
cf uups $serviceName -p $serviceData

set -e

return 0

The result with two parameters:

"\\\"encryptionKey\\\":\"\"\\\"$encryptionKey\\\"}": "",
"{\\\"containerName\\\":\"\"\\\"$objectStorageContainerDev\\\"": ""
  • Why in the world are you saying objectStorageCupsConfigData=''{\"containerName\":""\"$objectStorageContainerDev\"}''?  You’ve got two null strings ('') in there.  And then you use $objectStorageCupsConfigData without quoting it! You should always quote your shell variable references (e.g., "$objectStorageCupsConfigData") unless you have a good reason not to, and you’re sure you know what you’re doing. – G-Man Feb 20 '18 at 23:27
  • @G-Man That worked. Now the problem is that apparently the cf command that I am executing requires a single quote at the beginning and at the end of the JSON. This is the error I get: Incorrect Usage. Requires an argument USAGE: cf update-user-provided-service SERVICE_INSTANCE [-p CREDENTIALS] [-l SYSLOG_DRAIN_URL] [-r ROUTE_SERVICE_URL] Pass credential parameters as JSON to create a service non-interactively: cf update-user-provided-service SERVICE_INSTANCE -p '{"key1":"value1","key2":"value2"}' – Alan Robles Feb 21 '18 at 1:58
  • @G-Man however if I do the following objectStorageCupsConfigData='{\"containerName\":""\"$objectStorageContainerDev\",\"encryptionKey\":""\"$encryptionKey\"}' createCUPS "aa-contact-bags-objectStorage-config" "$objectStorageCupsConfigData" I get no error but the JSON in the server looks like this: { "\\\"encryptionKey\\\":\"\"\\\"$encryptionKey\\\"}": "", "{\\\"containerName\\\":\"\"\\\"$objectStorageContainerDev\\\"": "" } – Alan Robles Feb 21 '18 at 2:04
  • 1
    (1) Please don’t use strikeout mode like that unless you really have a good reason for including the wrong thing in your post. Just make the change; we can look at the revision history if we want to.  (2a) Don’t post multi-line messages in comments under your own question (or answer).  (2b) Please don’t say things like “the cf command that I am executing” [yields the following error message].  (2c) In general, don’t add information to your question in comments; edit your question to make it clearer and more complete, showing what command produced what response. – G-Man Feb 21 '18 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.