0
I'm getting weird results when trying to capture curl's response headers in a variable:
pattern="< Content-Length: "
val=$(curl --verbose \
--request POST --data "desc=hello world" \
example.org 2>&1 | \
grep "$pattern" | sed -e "s/$pattern/xxx/")
echo "====="
echo "aaa $val bbb"
echo "====="
This results in the following output:
$ ./test.sh
=====
bbbxxx438
=====
Why is the "aaa " being dropped and the variable contents being appended to the end of the line?