For example, here is my program's output (bspwm, if you wanted to know):
{
"id": 29360131,
"splitType": "vertical",
"splitRatio": 0.5,
"birthRotation": 90,
"vacant": true,
"sticky": false,
"private": false,
"locked": false,
"presel": null,
"rectangle": {
"x": 0,
"y": 0,
"width": 1920,
"height": 1200
},
"firstChild": null,
"secondChild": null,
"client": {
"className": "Termite",
"instanceName": "termite",
"borderWidth": 1,
"state": "floating",
"lastState": "tiled",
"layer": "normal",
"lastLayer": "normal",
"urgent": false,
"visible": true,
"icccmFocus": true,
"icccmInput": true,
"minWidth": 10,
"maxWidth": 0,
"minHeight": 19,
"maxHeight": 0,
"wmStatesCount": 0,
"wmState": [],
"tiledRectangle": {
"x": 0,
"y": 0,
"width": 958,
"height": 1198
},
"floatingRectangle": {
"x": 638,
"y": 394,
"width": 642,
"height": 410
}
}
}
I want to check if "state"
is not "tiling"
. In this case, it is "floating"
.
echo "$str" | grep -oP '"state":"\K([^"]*)'
– BinaryZebra Feb 24 at 6:02<your program> | grep -q '"state": *"tiling"'
|| echo not tiling` Or use a json parser likejq
. – cuonglm Feb 24 at 6:22