I have a Postgres console command createdb appname_production_master
, which return error exit code if the database with this name already exists.
我有一个Postgres控制台命令createdb appname_production_master,如果已存在具有此名称的数据库,则返回错误退出代码。
Is it possible to make this command do not return any exit code?
是否可以使此命令不返回任何退出代码?
2 个解决方案
#1
19
Just ignore the exit code, for example like this.
只需忽略退出代码,例如这样。
createdb appname_production_master || true
#2
1
Unix commands always return exit codes, but you need not respond to the exit code.
Unix命令总是返回退出代码,但您不需要响应退出代码。
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
#1
19
Just ignore the exit code, for example like this.
只需忽略退出代码,例如这样。
createdb appname_production_master || true
#2
1
Unix commands always return exit codes, but you need not respond to the exit code.
Unix命令总是返回退出代码,但您不需要响应退出代码。
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