简体   繁体   中英

Difference between linux exit 1 vs false command

IN RPM installation i am using false command (in pre section) in case the rpm is already install. Despite executing false command , the rpm installation continues. But when i use "exit 1" , RPM installation fails.

Just want to know why "false" command is unable to stop execution.

false command just sets an exit code of 1 like this

$ false
$ echo $?
1
$

The script has to decide on what to do with this exit code, eg to stop execution with an exit $? . (Be careful $? always contains the exit code of the last executed command. After echo $? it contains the exit code of the echo command...)

Most time I use false only as a place holder while writing scripts or testing/debugging branches in scripts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM