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

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

In the rpm specification file, each line ends with || : || :

What is the meaning of || : || : and why is it?

+4
source share
5 answers

This ignores any error, so the rpm operation is not canceled.

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

+11
source

He swallows the exit code.

|| does a thing after it if the thing before its failure (i.e. has a non-zero exit code). : - do nothing command. Combine them together ...

+3
source
 `||` is OR operator. `:` means "do nothing". 

Your statement says: β€œMake a soft link or do nothing”

+2
source

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

command || /bin/true

IMHO, which makes it much more obvious to the next person who reads the bash script / spec file.

+2
source

It just means OR. You can try a little testing like this

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

If the file will not be displayed, an echo will be printed. Try with an existing file, it will not

+1
source

All Articles