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
chicks
  • 3,793
  • 10
  • 27
  • 36
scripter
  • 1
  • 1

1 Answers1

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
Gilles Quénot
  • 1,313
  • 10
  • 17
  • 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. – Gordon Davisson Mar 07 '18 at 07:33