I found a line in one of the shell scripts,
cd /tmp || exit 2
What does this double pipe "||" mean?
Can any one tell what it is doing?
Thanks in advance.
I found a line in one of the shell scripts,
cd /tmp || exit 2
What does this double pipe "||" mean?
Can any one tell what it is doing?
Thanks in advance.
if the first command succeed the second will never be executed
Or
if the cd /tmp fails it will execute 'exit 2'
If the exit status of the first command (cd /tmp) is not 0, then execute the second command (exit 2).
It's the opposite of '&&', where the second command is executed only if the exit status of the preceding command is 0.
For example:
$ ls this_file_does_not_exist.txt || echo KO
ls: cannot access this_file_does_not_exist.txt: No such file or directory
KO
$ ls this_file_exist.txt && echo OK
this_file_exist.txt
OK
Thery are both correct but i believe that you are looking for this:
the || in a script "shell or perl" refers to: OR.
|| is equal to OR
So all your scripts are saying do this || \ OR this