2

Command based on Rampion's command

screen /bin/sh -c '/usr/bin/man `cat "$@"` > /tmp/manual | less /tmp/manual || read'

|| read does not mean or in the command. read seems to be a built-in -command about which I did not find explanation in my OS X's manuals.

What does || mean in the command?

Community
  • 1
  • 1
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

2 Answers2

5

|| is nearly 'or' operator.

In the code example above it will first run less /tmp/manual and if it returns a value that is not true it will run read. If the first command returns a true value then the read command is not performed because of short circuiting.

Thanks to Michiel: please note that the operator is not commutative such that it is not mathematical OR.

Community
  • 1
  • 1
MitMaro
  • 5,607
  • 6
  • 28
  • 52
  • 3
    @MitMaro This is a nitpick, but the behaviour you describe is not equivalent to a logical or. A real 'or' is commutative, i.e. (a \/ b) = (b \/ a). – Michiel Buddingh Jul 12 '09 at 21:43
  • @Michiel: Your point is excellent! - I was confused because my both commands are successful but only the first one is run. --- This suggests me that I can remove the last part of my code. – Léo Léopold Hertz 준영 Jul 12 '09 at 22:25
3

What MitMaro said. It's a parameter for the shell, or /bin/sh in this case. (Technically it's not a "parameter" (that's a different term) but it's part of the shell's "grammar.")

For details, you can read the man page on sh. What you're looking for is under the "Lists" section.

Snippet:

An OR list has the form

command1 || command2

command2 is executed if and only if command1 returns a non-zero exit status.

The return status of AND and OR lists is the exit status of the last command executed in the list.

exclsr
  • 3,329
  • 23
  • 27