Using jq with bash to run command for each object in array

前端 未结 5 1501
眼角桃花
眼角桃花 2021-02-02 07:48

How can I run a Bash command for every JSON object in a JSON array using jq? So far I have this:

cat credentials.json | jq -r \'.[] | .user, .date, .         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-02 08:30

    You could have jq output the commands to execute, something like

    .[] | "mycommand \(.user|@sh) \(.date|@sh) \(.email|@sh)"
    

    Then execute it. Something like

    bash <(jq -r '.[] | "mycommand \(.user|@sh) \(.date|@sh) \(.email|@sh)"' foo)
    

提交回复
热议问题