I'm trying to store the headers (from stderr) of a curl response in a variable and pipe the body (from stdout) to grep.
Here's my current attempt:
{
HEADERS=$(curl -vs $URL 2>&1 1>&3-)
echo "$HEADERS"
} 3>&1 | grep "regex" >> filename
echo "$HEADERS"
When I run the script with bash -x script.sh
I see + HEADERS='...'
with the expected output, but I can't access them with either $HEADERS
nor "$HEADERS"
inside and outside the inline group.
The body get's piped through as expected.