使用jq解析Launchd中的JSON [英] Using jq to parse JSON in launchd

查看:157
本文介绍了使用jq解析Launchd中的JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个shell脚本,该脚本评估充满JSON文件的文件夹,该文件夹在直接调用时运行良好,但从启动运行时失败.具体来说,启动在此行失败:

I have a shell script that evaluates a folder full of JSON files which runs fine when invoked directly but fails when run from launchd. Specifically, launchd fails on this line:

current_file_snapshots=$(cat $current_file | jq '.snapshots | length')

因为:

jq: command not found

我浏览了jq文档以弄清楚这一点,但是没有提到这个问题.我还无法弄清楚如何使jq(或任何类似的第三方工具)通过启动工作.

I looked through the jq docs to figure this out, but there's no mention of this problem. I haven't been able to figure out how to get jq (or any similar third party tool) to work through launchd.

谢谢!

推荐答案

嗯,看来我假设launchd与普通的bash shell共享相同的PATH.明确指出JQ住的地方似乎可行:

Ahh, looks like I assumed that launchd shared the same PATHs as my normal bash shell. Explicitly spelling out where JQ lives seemed to work:

因此,我在文件的顶部添加了

So at the top of the file I added:

JQ=/usr/local/bin/jq

并将所有'jq'实例替换为:

and replaced all instances of 'jq' with:

$JQ

这篇关于使用jq解析Launchd中的JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆