Re: psql exit status with multiple -c or -f - Mailing list pgsql-hackers

From Justin Pryzby
Subject Re: psql exit status with multiple -c or -f
Date
Msg-id 20190131034523.GH13248@telsasoft.com
Whole thread Raw
In response to Re: psql exit status with multiple -c or -f  (Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>)
List pgsql-hackers
At Tue, 18 Dec 2018 10:24:39 -0600, Justin Pryzby <pryzby@telsasoft.com> wrote:
> I think ON_ERROR_STOP would control whether the script stops, but it should
> fail the exit status should reflect any error in the last command.  The
> shell does that even without set -e.

Let me correct my own language:

| I think ON_ERROR_STOP would control whether the script stops, but 
| the exit status should reflect any error in the last command.  The
| shell does that even without set -e.

What I mean is that "the exit status of the shell reflects the status of the
last command".  That's why you'll see at the bottom of shscripts an "exit 0"
which might seem to be implied.  Actually falling off the end of the script is
same as "exit" which is same as "exit $?" which may be nonzero if the preceding
command was a conditional/test, like:

for ...
 if ...
 fi
done
# without this, script will variously "fail" due to conditional evaluating to
# false:
exit 0

So I'm pointing out serious concern if psql would return 0 if last command
failed, a case where it's currently exiting with status 1.

Justin


pgsql-hackers by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: psql exit status with multiple -c or -f
Next
From: Michael Paquier
Date:
Subject: Re: A few new options for vacuumdb