piping curl's response headers

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?

AnC

Posted 2009-11-27T20:53:31.873

Reputation:

Answers

1

Turns out it was due to carriage returns - fixed with a simple s/\r//.

AnC

Posted 2009-11-27T20:53:31.873

Reputation: 294