jq 包括默认搜索路径

jq include default search path

我想在 /usr/lib/jq/mytest.jq 中放置一个函数定义以包含在我的 jq 脚本中。

来自manual :

The default search path is the search path given to the -L command-line option, else ["~/.jq", "$ORIGIN/../lib/jq", "$ORIGIN/../lib"].

既然 jq 在 /usr/bin 中,/usr/bin/../lib/jq 不应该在搜索路径中吗?我无法让这个命令工作:

jq -n 'include "mytest";'

在命令中添加 -L /usr/lib/jq 可以,或者我可以创建一个 ~/.jq/mytest.jq 也可以。但是,我想使用 ~/.jq 文件进行启动。如何在不在命令行上指定 -L 的情况下拥有启动脚本 包含搜索路径??

How can I have a startup script and a include search path without specifying -L on the command line?

使用模块元数据功能,例如:

include "mytest" {"search": "/usr/local/lib/jq"}; 

插图

$ cat /usr/local/lib/jq/mytest.jq
def go: "hello";

$ jq -n 'include "mytest" {"search": "/usr/local/lib/jq"}; go'
"hello"

后记

如果您认为当前版本的 jq (1.6) 与 https://stedolan.github.io/jq/manual/v1.6/ 上的相应文档不匹配 请在 https://github.com/stedolan/jq/issues

提交报告