0
jq '.issues[].fields.subtasks[].fields | .issuetype.subtask' 1.json

works as expected (getting "true" as output) when trying to put command above as variable

for custom_field in `cat 1.json | jq .issues[].fields.subtasks[].fields | .issuetype.subtask`; do
      echo $customfield
done

getting:.

issuetype.subtask: command not found

1 Answer 1

2

Try this :

for custom_field in $(
    jq '.issues[].fields.subtasks[].fields | .issuetype.subtask' 1.json
); do
      echo "$customfield"
done

Or better with a while loop if you have values with spaces :

while IFS= read -r customfield; do
    echo "$customfield"
done < <(jq '.issues[].fields.subtasks[].fields | .issuetype.subtask' 1.json)

Note :

  • you need to 'quote' the expression
  • jq can read file by itself, no need cat
  • stop using backticks ` in 2018 please use $( )
  • < <( ) is a bash-only feature, not available in other shells (or even in bash when it's invoked as sh). So start your script with a bash shebang #!/bin/bash or #!/usr/bin/env bash and don't override that by running the script with the sh command
1
  • 1
    Note that <( ) is a bash-only feature, not available in other shells (or even in bash when it's invoked as sh). So start your script with a bash shebang (#!/bin/bash or #!/usr/bin/env bash) and don't override that by running the script with the sh command. Mar 7, 2018 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.