Expanding Bash shell variable in Curl in Cmder

為{幸葍}努か 提交于 2019-12-11 17:23:10

问题


On a Window 7 machine in Cmder emulator in Git bash window, I'm trying to capture the ISO-formatted current date:

$ date +%s
1513354497

to be sent inside the body of curl POST request:

$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"     

Here's the exception I'm getting:

<!--                                                                                                              
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;]                                                                               

-->   

How do I pass the date +%s to curl for proper expansion in bash?

Thank you.


回答1:


Instead of '... ,"updated":"'"date +%s"'"}', use '... ,"updated":"'"$(date +%s)"'"}' See https://stackoverflow.com/a/30327963/4486184



来源:https://stackoverflow.com/questions/47836652/expanding-bash-shell-variable-in-curl-in-cmder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!