在 JQ 中使用具有多个参数的 C 数学函数
Using C math functions with more than one argument in JQ
如何在 JQ 中使用带有多个参数的 C 数学函数?手册中没有示例。它只说:
C math functions that take a single input argument (e.g., sin()
) are available as zero-argument jq
functions. C math functions that take two input arguments (e.g., pow()
) are available as two-argument jq functions that ignore .
C math functions that take three input arguments are available as three-argument jq functions that ignore .
我已经弄清楚如何将单个输入参数函数实现为零参数 jq 函数:
> echo '{"a": 10.12}' | jq '.a | floor'
10
如何使用 pow
之类的东西?
手册中 "jq functions that ignore .
" 是什么意思?他们是否忽略了管道输入的内容,因为他们不将其作为参数,与仅从管道中获取参数的单个输入参数情况相反?
很简单,用;
:
分隔函数参数即可
> echo '{"a": 10.12}' | jq '. | pow(.a;.a)'
20051775181.748566
关于忽略.
的jq函数的含义:
似乎在单输入参数函数的情况下,如 floor
,实际发生的是使用默认参数 .
,因此无需实际提及任何参数。
对于 2 个或更多输入参数的情况,这当然不再适用,因此不应用默认参数并且必须显式传递两个参数。
如何在 JQ 中使用带有多个参数的 C 数学函数?手册中没有示例。它只说:
C math functions that take a single input argument (e.g.,
sin()
) are available as zero-argumentjq
functions. C math functions that take two input arguments (e.g.,pow()
) are available as two-argument jq functions that ignore.
C math functions that take three input arguments are available as three-argument jq functions that ignore.
我已经弄清楚如何将单个输入参数函数实现为零参数 jq 函数:
> echo '{"a": 10.12}' | jq '.a | floor'
10
如何使用 pow
之类的东西?
手册中 "jq functions that ignore .
" 是什么意思?他们是否忽略了管道输入的内容,因为他们不将其作为参数,与仅从管道中获取参数的单个输入参数情况相反?
很简单,用;
:
> echo '{"a": 10.12}' | jq '. | pow(.a;.a)'
20051775181.748566
关于忽略.
的jq函数的含义:
似乎在单输入参数函数的情况下,如 floor
,实际发生的是使用默认参数 .
,因此无需实际提及任何参数。
对于 2 个或更多输入参数的情况,这当然不再适用,因此不应用默认参数并且必须显式传递两个参数。