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
=====
 bbbxxx438
=====

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

share|improve this question
add comment

1 Answer

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

share|improve this answer
add comment

Your Answer

 
discard

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