Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

Why is the "aaa " being dropped and the variable contents being appended to the end of the line?

share|improve this question

1 Answer 1

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.