【发布时间】:2016-12-29 15:26:27
【问题描述】:
标题可能不正确,因为我实际上不确定这是失败的地方。我有一个在一个目录中运行的 bash 脚本,以及一个我需要来自不同目录的值的 JSON 文件。我想将外部目录中的值复制到当前目录中相同的 JSON 文件中。
我正在使用 jq 来获取值,但我不知道如何从脚本运行所在目录之外的目录中获取值。
文件结构的相关位如下;
cloudformation
- parameters_v13.json
environment_files
- prepare_stack_files.json (the script this is run from)
- directory, changes based on where the script is pointed
- created directory where created files are being output
- GREPNAME_parameters.json
我感兴趣的 JSON 文件块如下所示;
[
{
"ParameterKey": "RTSMEMAIL",
"ParameterValue": "secretemail"
}
]
脚本需要从cloudformation/parameters_v13.json 获取“秘密邮件”并将其粘贴到GREPNAME_parameters.json 文件中匹配的RTSMEMAIL 字段中。
我一直在尝试以下操作,但没有成功 - 没有任何输出。也没有错误消息,只是空白输出。我知道 GREPNAME 路径是正确的,因为它在其他地方使用没有问题。
jq --arg email "$EMAIL" '(.[] | select(.ParameterKey == "RTSMEMAIL") | .ParameterValue) |= $email' ../cloudformation/parameters_v13.json | sponge ${GREPNAME}_parameters.json
【问题讨论】:
-
您的输入无法验证,如果您能提供完整的
json或示例文件,将会很有帮助。 -
对,对不起,把括号放在里面,这样它就可以算作一个完整的文件了
-
你对
jq --arg email "$EMAIL" '(.[] | select(.ParameterKey == "RTSMEMAIL") | .ParameterValue) |= $email'有什么期望,它给了我空白输出。 -
我期待
secretemail- 空白输出正是我难过的原因。