如何比较字符串和空格?

时间:2019-11-26 13:23:03

标签: bash jq

我正在修改位图脚本,并遇到了无法将字符串与空格进行比较的问题,select( .to.name == \"$to_status\"返回false,其中.to.name是“ ready for qa”而to_status是“ ready for qa”

 TO_STATUS="Ready to QA"

 transition_id=$(curl -s \
     -H "Authorization: Basic $token" \
     "$jira_url/rest/api/2/issue/$task/transitions" | \
     jq -r ".transitions[] | select( .to.name == \"$to_status\" ) | .id")

我尝试采用此post中的解决方案,但没有任何运气

transition_id=$(curl -s \
    -H "Authorization: Basic $token" \
    "$jira_url/rest/api/2/issue/$task/transitions" | 
    jq -r --arg to_status "$TO_STATUS" '
    .transitions[] 
    | select(.to."name"==$to_status) 
    | .id')

json

{
  "expand": "transitions",
  "transitions": [
    {
      "id": "11",
      "name": "Backlog",
      "to": {
        "name": "Backlog",
        "id": "10510"
      }
    },
    {
      "id": "51",
      "name": "Ready to QA",
      "to": {
        "name": "Ready for QA",
        "id": "10209"        
      }
    }
  ]
}

1 个答案:

答案 0 :(得分:1)

不要插值;通过meta: { "pagination": { "count": 3, "total": 4, "perPage": 3, "currentPage": 1, "totalPages": 2, "links": { "next": "http://127.0.0.1:8000/api/service/list?perPage=3&page=2" } } 作为参数。

to_status
相关问题