#jq コマンドと #shell の組み合わせで、 JSON 配列が空かどうかを条件判定する例
when Json array is empty
$ if [ $(echo '[]' | jq '. | length') -eq 0 ]; then echo empty; else echo non empty; fi
empty
when Json array is not empty
$ if [ $(echo '[1]' | jq '. | length') -eq 0 ]; then echo empty; else echo non empty; fi
non empty
Original by Github issue
$ if [ $(echo '[]' | jq '. | length') -eq 0 ]; then echo empty; else echo non empty; fi
empty
$ if [ $(echo '[1]' | jq '. | length') -eq 0 ]; then echo empty; else echo non empty; fi
non empty
Original by Github issue
Author And Source
この問題について(#jq コマンドと #shell の組み合わせで、 JSON 配列が空かどうかを条件判定する例), 我々は、より多くの情報をここで見つけました https://qiita.com/YumaInaura/items/c3df811d7d3e04374e95著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .