11

I have a Postgres console command createdb appname_production_master, which return error exit code if the database with this name already exists.

Is it possible to make this command do not return any exit code?

2 Answers 2

25

Just ignore the exit code, for example like this.

createdb appname_production_master || true
Sign up to request clarification or add additional context in comments.

2 Comments

Strictly speaking, this doesn't ignore the exit code, but it uses it in an expression that always succeeds.
"<<command>> || :" is another form that seems to work, where the colon is the null command that always succeeds
1

Unix commands always return exit codes, but you need not respond to the exit code.

When you run a command $? is set to the exit code of the process. As this happens for every command, simply running a different command after the first will change $?.

For example:

createdb appname_production_master # returns 1, a failure code
# $? is 1
/bin/true # always returns 0, success
# $? is 0

Here's another example:

/bin/false # returns false, I assume usually 1
echo $? # outputs 1
echo $? # outputs 0, last echo command succeeded

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.