filtering data using parameters

后端 未结 2 1494
陌清茗
陌清茗 2021-01-25 07:18

I have this command that is working..

cat  ~/Desktop/results.json |  jq \'.[] | .environmentStatuses[].deploymentResult | select(.key.entityKey.key==\"39583746-3         


        
相关标签:
2条回答
  • 2021-01-25 07:55

    When trying to use extra parameters in your filters, use the --arg option to pass them in. Don't rely on the shell to insert it into your filter string, keep that separate.

    jq --arg key "$enkey" '.[] |
      .environmentStatuses[].deploymentResult |
      select(.key.entityKey.key == $key) |
      .lifeCycleState' ~/Desktop/results.json
    
    0 讨论(0)
  • 2021-01-25 08:07

    This worked for me :

      jq '.[] | .environmentStatuses[].deploymentResult |
      select(.key.entityKey.key == "'$key'") |
      .lifeCycleState' ~/Desktop/results.json 
    

    --arg does not works as expected ...

    0 讨论(0)
提交回复
热议问题