I am trying to substitute a variable value from command line for a csh shell script
cat test.sh
#!/bin/csh
set verbose
set echo
/usr/bin/wget -O created.json --post-data="{ "version": "4.3", "merchant": { "bin": "000001" }, "order": { "customerProfileOrderOverideInd": "NO", "customerProfileFromOrderInd": "A", "orderDefaultAmount": "1050" }, "paymentInstrument": { "customerAccountType": "CC", "card": { "ccAccountNum": $1, "ccExp": "202406" } }, "profile": { "customerName": "Glgli", "customerAddress1": "EGL", "customerCity": "Aurora", "customerState": "CO", "customerZIP": "80011", "customerEmail": "[email protected]", "customerPhone": "81942636", "customerCountryCode": "US" } }" --header="OrbitalConnectionUsername: XXXXXXX" --header="OrbitalConnectionPassword: XXXXXXXX" --header="MerchantID: XXXXXX" --header="content-type: application/json" --no-cookies --no-check-certificate "https://some website"
I am executing the shell script as below
./test.sh <some card number>
But it is not reflecting the value and the profile is not getting created. If I hardcode the value of "ccAccountNum" the profile gets created successfully. I even tried with "-method=post" , "--body-data" and double quotes with $1. Both didn't worked. Please let me know what mistake I am doing.
PS:Because of some constraints I cannot use --post-file.
You can't nest
"quotes; with this:That first
"will start quoting, that second will stop quoting, that this will start quoting, etc. You can test this withecho:Which isn't what you want.
Instead, quote the literal JSON parts with
', then stop quoting, insert your$1as$1:qto insert it as literal, and start quoting with'again.This sounds confusing, and it is, but that's shell scripting for you.
Abbreviated, this is what it looks like: