0

How can I run multiple line commands in bash on OSX?

curl https://sandbox.checkout.com/api2/v2/customers/cust_8AB7845C-35D6-4BAD-BED0-D0D7F75C50F0/cards
    -H "Authorization: sk_093F4C8D-E608-4B8D-9B39-8C2491345864" 
    -H "Content-Type:application/json;charset=UTF-8"
    -X POST 
    -d '{
           "name" : "Miss Matt Quigley",
           "number" : "4242424242424242",
           "expiryMonth" : "06",
           "expiryYear" : "2018",
           "cvv" : "100",
           "billingDetails" : {
              "addressLine1" : "56 Layla Rue",
              "addressLine2" : "Junius Plain",
              "city" : "PortDeclan",
              "country" : "US",
              "phone" : {
                 "countryCode" : "44",
                 "number" : "12345678"
              },
              "postcode" : "ei104xh",
              "state" : "Anthony"
           }
        }'

When I paste it into my bash the formatting changes and it can't run as a result.

Alex Kokorin
  • 459
  • 5
  • 15
  • try adding a "\" character before every linefeed – Srini Apr 11 '18 at 16:39
  • 2
    Every linefeed that isn't in quotes, that is. You don't want to add backslashes inside the JSON. – Charles Duffy Apr 11 '18 at 16:39
  • This is arguably a simpler version of [How can I split a shell command over multiple lines when using an `if` statement?](https://stackoverflow.com/questions/18599711/how-can-i-split-a-shell-command-over-multiple-lines-when-using-an-if-statement). As any answer there *does* also answer this question, it's arguably close-as-dupable immediately, but I'm looking for whether we have anything even closer. – Charles Duffy Apr 11 '18 at 16:40
  • BTW, you could also put the whole thing in an array and run it that way. Put a new line `curl_cmd=(` at the beginning, a `)` at the end, and then you can execute it later by running `"${curl_cmd[@]}"`. That technique is also discussed (albeit in a different context) in [BashFAQ #50](http://mywiki.wooledge.org/BashFAQ/050). – Charles Duffy Apr 11 '18 at 16:42
  • I'd put the url in a variable, the data in a variable, the curl options in an array, and call it like `curl "${opts[@]}" -d "$data" "$url"` – glenn jackman Apr 11 '18 at 16:44

0 Answers0