I made this utility (part of utility code)

#!/bin/bash url_prefix=' url_suffix='java-tutorial' curl -v $url_prefix$url_suffix | grep -m 1 '>next' | cut -d '"' -f 4 >temp.html 

If I remove -v from curl commnad;it starts saying failed to write body. I am not able to understand why this happens. full code is available at

3

2 Answers

curl -v does not cause or suppress your error, but the error can get lost in the other log messages -v writes.

curl -v only determines whether verbose logging is written to stderr; it does not impact your pipeline in any other way.


The error is actually caused by curl | grep -m 1.

To explain the error, then:

grep -m 1 tells grep to quit after the first match.

This means that all subsequent writes by curl into the FIFO read by grep will cause an EPIPE error, as the program on the other end of the pipeline is no longer reading. Consequently, curl cannot write the rest of the body, so you get the error in question.

However, since the rest of your pipeline doesn't actually use any of that body content, this is expected and harmless.


If you want to suppress this error, letting curl write the whole output even if grep doesn't need it, you can do that easily enough:

content=$(curl -v "$url_prefix$url_suffix") printf '%s\n' "$content" | grep -m 1 '>next' | ... 

The command substitution reads the entire output of curl, so the error doesn't take place.

14

As per man page of curl , by using verbose, you can see more debugging information about curl operation It's failing in your case, because you are doing further operation on that 'more information', which not present if you are note using verbose mode(-v)

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy