The || operator

The || operator

You can use the || operator to execute a command and, if it fails, execute the next command in the command list. For example:

   cmd1 || cmd2

cmd1 is executed and its exit status examined. If cmd1fails then cmd2 is executed. This is a terse notation for:

   cmd1
   if 	test $? -ne 0
   then
     cmd2 
   fi

[Home] [Search] [Index] This site maintained by unixhelp@math.rutgers.edu
This page was last updated on September 05, 2006 at 10:30 am and is maintained by webmaster@math.rutgers.edu.
For questions regarding courses and/or special permission, please contact mclausen@math.rutgers.edu.
For questions or comments about this site, please contact help@math.rutgers.edu.
© 2012 Rutgers, The State University of New Jersey. All rights reserved.