我必须进行从应用程序输出,产生JSON输出。必须检查“代码”申请,如果它是不同于0做出一些动作。决定在bash脚本做到了,但现在我不能找到一种方法(JQ完全小白),以布尔值false或退出0进入下一开关罩。
这就是我已经试过:
app | jq -r 'if (.code != 0 ) then (@sh 'exit 1') else empty end'
app | jq -r 'if (.code != 0 ) then (boolean (false)) else empty end'
但所有的时间这样的错误:
jq: error: syntax error, unexpected INVALID_CHARACTER (Unix shell quoting issues?) at <top-level>, line 1:
if (.code != 0 ) then (@sh 'exit 1') else empty end
jq: 1 compile error
exit status 3
这就是输入JSON
和输出是广泛的(这不是完整的输出)
{
"code" : 0,
"description" : "Success",
"response" : {
"properties" : [
{
"name" : "name",
"value" : "\"cam_src_pipe\"",
"param" : {
"description" : "The name of the current Gstd session",
"type" : "gchararray",
"access" : "((GstdParamFlags) READ | 234)"
}
},
{
"name" : "description",
"value" : "\"imxv4l2videosrc imx-capture-mode=0 ! imxipuvideotransform deinterlace=true ! interpipesink name=cam_src caps=video/x-raw,width=640,height=480,framerate=30/1 sync=true async=false forw
ard-eos=true\"",
"param" : {
"description" : "The gst-launch like pipeline description",
"type" : "gchararray",
"access" : "((GstdParamFlags) READ | 234)"
}
},
{
"name" : "elements",
"value" : "((GstdList*) 0x560c63a0)",
"param" : {
"description" : "The elements in the pipeline",
"type" : "GstdList",
"access" : "((GstdParamFlags) READ | 224)"
}
},
我得布尔值false或退出1着手猛砸
我不是一个专家JQ,但你不能使用类似下面?你可以存储到你的jq解析什么是变量,并根据需要进行。
code=$(app | jq '.code')
if [ $code -eq 0 ]
then ...
else ...
fi