I need to create a bunch of strings using heredocs which I want to store in an array so that I can run them all through processes later. For example
IFS='' read -r -d '' data << END
{
"my": "first doc"
}
END
IFS='' read -r -d '' data << END
{
"my": "second doc"
}
END
I know I could append to an array of docs using a construction like
docs+=("${data}")
after each heredoc, but is there a slick way I can do it directly in the read command without assigning index values (so I can change the order, add others in the middle, etc without it being awkward)?
jqrather than bash arrays.read -d ''reads up to the next NUL, yourreadcommands have nonzero exit status, so if this code were run withset -e(which is bad practice anyhow) it would fail upon reaching them.