字符串插值中的jq过滤表达式
jq filter expression in string interpolation
我一直在尝试将数组缩减为要在字符串插值中使用的字符串。
例如。
input = ["123", "456"]
expected output = array=123,456
这是我的尝试
$ echo '["123", "456"]' | jq 'array=\(.|join(","))'
jq: error: syntax error, unexpected INVALID_CHARACTER (Unix shell quoting issues?) at <top-level>, line 1:
array=\(.|join(","))
jq: 1 compile error
echo '["123", "456"]' | jq -r '"array=" + join(",")'
使用字符串插值 \(.)
,您可以执行如下操作。你的想法几乎是正确的,但是使用 \(..)
的插值需要过滤器出现在一个字符串中,并且在反斜杠
之后的括号内定义要使用的表达式
jq --raw-output '"array=\(join(","))"'
我一直在尝试将数组缩减为要在字符串插值中使用的字符串。
例如。
input = ["123", "456"]
expected output = array=123,456
这是我的尝试
$ echo '["123", "456"]' | jq 'array=\(.|join(","))'
jq: error: syntax error, unexpected INVALID_CHARACTER (Unix shell quoting issues?) at <top-level>, line 1:
array=\(.|join(","))
jq: 1 compile error
echo '["123", "456"]' | jq -r '"array=" + join(",")'
使用字符串插值 \(.)
,您可以执行如下操作。你的想法几乎是正确的,但是使用 \(..)
的插值需要过滤器出现在一个字符串中,并且在反斜杠
jq --raw-output '"array=\(join(","))"'