What does the || : in this line of bash script from an rpm spec file do?

北城以北 提交于 2019-12-19 21:23:48

问题


ln -s /var/log/$SERVICE_NAME $RPM_INSTALL_PREFIX/logs || :

In the rpm spec file every line ends with || :

What is the significance of the || : and why is it there?


回答1:


It causes any error to be ignored so that the rpm operation isn't canceled.

|| causes the next command to run if the previous command failed, and : always succeeds.




回答2:


It swallows the exit code.

|| does the thing after it if the thing before it fails (i.e., has a non-zero exit code). : is the “do nothing” command. Put them together…




回答3:


`||` is OR operator. `:` means "do nothing". 

Your statement says, "do the soft linking or do nothing"




回答4:


I know others have answered, but I prefer to put:

command || /bin/true

IMHO that makes it a lot more obvious to the next person who is reading the bash script/spec file.




回答5:


It is simply means OR. You can try small testing like this

ls nofile-here-like || echo 'Not here'

If file not there echo will printed. Try with existing file, it will not



来源:https://stackoverflow.com/questions/5737978/what-does-the-in-this-line-of-bash-script-from-an-rpm-spec-file-do

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!