在Git bash窗口的Cmder模拟器中的Window 7机器上,我正在尝试捕获ISO格式的当前日期:
$ date +%s
1513354497
要在curl POST请求体内发送:
$curl.sh -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{"restricted":true,"marquardtRole":"ContentStreamReservedTagMARQUARDTBIWEEKLYUPDATE","description":"Bi-weekly update covering Marquee development and go-to-market functions.","assetClasses":["Commodities","Credit","Currencies","Economics","Emerging Markets","Equities Macro","Equities Micro","Interest Rates","Prime Services"],"authoringDivision":"SECDIV","titlePattern":"(?i)Marquardt Weekly Update.*","name":"Marquardt BIWEEKLY UPDATE", "updatedBy": "d37286ac275911d788f1b1f11ac60222","updated":"'"date +%s"'"}' "http://localhost.abc.com:8000/maq-app-cnts/services/pubs"
以下是我得到的例外情况:
<!--
The request did not match any of the requests defined for this endpoint.
Request definition 1: The JSON object in the body does not conform to the schema
error: instance type (string) does not match any allowed primitive type (allowed: ["integer"])
level: "error"
schema: {"loadingURI":"definition:/DateTimeInteger#","pointer":""}
instance: {"pointer":"/updated"}
domain: "validation"
keyword: "type"
found: "string"
expected: ["integer"]
-->
如何将date +%s
传递给curl以便在bash中正确扩展?
谢谢。
答案 0 :(得分:0)
而不是'... ,"updated":"'"date +%s"'"}'
,请使用'... ,"updated":"'"$(date +%s)"'"}'
见https://stackoverflow.com/a/30327963/4486184