I am trying to save the headers (from stderr) of the response in a variable and pass the body (from stdout) to grep.
Here is 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='...'the expected output, but I can’t access them from $HEADERSeither "$HEADERS"inside or outside the built-in group.
The body gains access to the pipeline as expected.
source
share