Ignoring Linux command exit code

I have a Postgres createdb appname_production_master console command that returns an exit code with an error if a database with this name already exists.

Is it possible that this command does not return an exit code?

+6
source share
2 answers

Just ignore the exit code, for example, for example.

 createdb appname_production_master || true 
+18
source

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

When running the command $? The process exit code is set. Since this happens for each command, just run another command after the first change to $? .

For instance:

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

Here is another example:

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

Source: https://habr.com/ru/post/909288/


All Articles