what does " ||" mean? ( Double pipe) | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

what does " ||" mean? ( Double pipe)

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-30-2007
Muktesh Muktesh is offline
Registered User
 
Join Date: Aug 2007
Last Activity: 6 December 2007, 9:02 AM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb what does " ||" mean? ( Double pipe)

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.
Sponsored Links
    #2  
Old 08-30-2007
andryk's Avatar
andryk andryk is offline Forum Advisor  
Registered User
 
Join Date: Sep 2003
Last Activity: 5 June 2008, 4:15 AM EDT
Posts: 448
Thanks: 0
Thanked 1 Time in 1 Post
if the first command succeed the second will never be executed
Or
if the cd /tmp fails it will execute 'exit 2'
Sponsored Links
    #3  
Old 08-30-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
 
Join Date: Apr 2002
Last Activity: 20 December 2009, 10:56 AM EST
Location: Italy
Posts: 370
Thanks: 0
Thanked 0 Times in 0 Posts
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:


Code:
$ 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

    #4  
Old 09-12-2007
car2nst2006 car2nst2006 is offline
Registered User
 
Join Date: Aug 2007
Last Activity: 29 July 2011, 9:40 AM EDT
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk command to replace ";" with "|" and ""|" at diferent places in line of file shis100 Shell Programming and Scripting 7 03-16-2011 08:59 AM
Splitting text string with "|" pipe delimiters alanp36 Shell Programming and Scripting 4 06-03-2010 04:37 AM
Encoding Problem while using "|" (PIPE) as delimiter from Mainframe to Unix seshendra UNIX for Dummies Questions & Answers 1 02-20-2008 04:36 AM
By angle-brackets/"pipe" button doesn't work? riwa Linux 1 04-02-2006 06:43 PM



All times are GMT -4. The time now is 12:45 AM.