Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

According to Using "&&" is not effective for cURL submit form (don't execute second line if first line fails)

In below code; first line is curl submit; second line is for queuing:

curl -b cookies.txt \
    -d title="$(sed '1,/sblmtitle/d;/slpstitle/,$d' sedut.html)" \
    -d taxonomy%5Btags%5D%5B1%5D="$(
        sed '1,/sblmkategori/d;/slpskategori/,$d' sedut.html
    )" \
    -d teaser_include=1 \
    -d body="$(sed '1,/sblmkonten/d;/slpskonten/,$d' sedut.html)" \
    -d field_source%5B0%5D%5Burl%5D="$(
        sed '1,/sblmurl/d;/slpsurl/,$d' sedut.html
    )" \
    -d changed= \
    -d form_build_id=form-424f851ad50bd4781c8c25ab7efd5c4c \
    -d form_token=0e7cc7437faf816f1ecd96087286bda9 \
    -d form_id=post_node_form \
    -d op=Save http://www.web.org/submit/post &&
for file in $(ls *.html | sort -r | tail -1); do
    mv $file sedut.html

If cURL fails to submit, it will print out sedut.html contents. If cURL success submitting, it will print nothing.

But cURL always giving 0 no matter if it success or failed in submitting.

I think the best workflow is "If cURL print nothing, run second line" and "If cURL print something, don't run second line"

I've just looked linux if command but still have no idea how to implement this because the example have different case.

share|improve this question
up vote 2 down vote accepted

So you hit upon the key here, if curl's output is different then you can test for it. First you can direct that to a file. Next you can leverage the -s option from test:

-s file True if file exists and has a size greater than zero.

Here is some example code:

curl -b cookies.txt ... -o /tmp/curl_output
if [ -s /tmp/curl_output ]; then
  do failure stuff here
  do successful stuff here

Another implementation for academic reasons:

if curl -b cookies.txt ... 2>&1 | grep 'some line from sedut.html' >/dev/null 2>&1; then 
  do failure stuff here
  do successful stuff here
share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.