我的任务组 bash 脚本中目前有以下内容
jq --argjson timestamp "$`date +%s`" '.common |= . + {"TimeValue": $timestamp }' ${service}/${env}.json > tmpfile && mv tmpfile ${service}/${env}.json
我的问题是这部分
"$`date +%s`"
当任务运行时,我收到以下错误
jq: invalid JSON text passed to --argjson
Use jq --help for help with command-line options,
因此,如果我编辑现有版本并将其更改为以下内容,一切都会正常:
"$(date +%s)"
问题是,当我在任务组中更改为上述内容时,它现在认为我正在尝试添加一个我不想要的新参数。
我该如何解决这个问题?
您可以通过以下方式之一更改为喜欢。
jq --argjson timestamp `date +%s` '.common |= . + {"TimeValue": $timestamp }' ${service}/${env}.json > tmpfile && mv tmpfile ${service}/${env}.json
或
timestamp=`date +%s`
jq --argjson timestamp $timestamp '.common |= . + {"TimeValue": $timestamp }' ${service}/${env}.json > tmpfile && mv tmpfile ${service}/${env}.json