【问题标题】:Expanding Bash shell variable in Curl in Cmder在 Cmder 中的 Curl 中扩展 Bash shell 变量
【发布时间】:2018-05-29 22:02:13
【问题描述】:

在 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: [&quot;integer&quot;])          
    level: &quot;error&quot;                                                                                      
    schema: {&quot;loadingURI&quot;:&quot;definition:/DateTimeInteger#&quot;,&quot;pointer&quot;:&quot;&quot;}    
    instance: {&quot;pointer&quot;:&quot;/updated&quot;}                                                          
    domain: &quot;validation&quot;                                                                                
    keyword: &quot;type&quot;                                                                                     
    found: &quot;string&quot;                                                                                     
    expected: [&quot;integer&quot;]                                                                               

-->   

如何将date +%s 传递给 curl 以便在 bash 中正确扩展?

谢谢。

【问题讨论】:

标签: unix curl git-bash conemu cmder


【解决方案1】:

'... ,"updated":"'"$(date +%s)"'"}'代替'... ,"updated":"'"date +%s"'"}'https://stackoverflow.com/a/30327963/4486184

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-31
    • 2011-05-08
    • 2017-01-27
    • 2017-08-18
    • 1970-01-01
    • 1970-01-01
    • 2012-06-30
    • 1970-01-01
    相关资源
    最近更新 更多