Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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" \ 2>&1 | \
    grep "$pattern" | sed -e "s/$pattern/xxx/")

echo "====="
echo "aaa $val bbb"
echo "====="

This results in the following output:

$ ./

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

share|improve this question

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

share|improve this answer

You must log in to answer this question.