本文介绍了在Cmder中的Curl中扩展Bash shell变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Git bash窗口中Cmder模拟器的Windows 7计算机上,我试图捕获ISO格式的当前日期:

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

要发送到卷发体内POST请求:

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"

这里是例外我得到:

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

-->

如何通过日期+%s 为使bash适当扩展而卷曲?

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

谢谢。

推荐答案

而不是'..., updated:' date +%s '}',使用'..., updated:' $(date +%s)'}'
请参见

这篇关于在Cmder中的Curl中扩展Bash shell变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 18:22