【发布时间】:2021-03-27 23:10:22
【问题描述】:
我需要执行cat build.json | jq '.Stage*.Name' 5 次,其中* 是一个从1 到5 的数字。
我试过了:
for (( c=1; c<5; c++ ))
do
echo $c
cat build.json | jq '.Stage${c}.Name'
done
我得到了这个错误:
jq: error: syntax error, unexpected '$', expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
.Stage${c}.Name
jq: 1 compile error
我该如何正确地做到这一点?
【问题讨论】:
-
我不确定你是否真的需要一个 shell 循环。实际任务是什么?
-
为了记录,你需要双引号才能工作;但是使用
--arg是一个更好的解决方案。另见stackoverflow.com/questions/6697753/…