LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-23-2006, 06:07 PM   #1
rollo
Member
 
Registered: Apr 2004
Location: France
Distribution: Debian Sid (Kanotix)
Posts: 237

Rep: Reputation: 30
Question What does "| |" mean in a script


5-second question here. What does the "||" mean in a script, like this one:

Code:
test -x /usr/sbin/anacron || run-parts --report /etc/cron.weekly
(Tricky searching this one because the character in question is ignored by search engines.)
 
Old 11-23-2006, 06:12 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
It means "or". If the left hand side returns a non-zero error code, the right hand side is run. This is complementary to && "and" where the right hand side is run if the left hand side returns no error (error code 0).

In this case, if /usr/sbin/anacron is not executable, then run-parts --report /etc/cron.weekly is executed
 
Old 11-23-2006, 06:15 PM   #3
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
two pipes, ||, is the almost universal logical OR operator.

literal: this or that
programming: this || that

that code snippet tests if /usr/sbin/anacron is an executable, and should that test fail (for any reason, the file not exist, or the file is not executable) "run-parts --report /etc/cron.weekly" is executed.

 
Old 11-23-2006, 06:15 PM   #4
rollo
Member
 
Registered: Apr 2004
Location: France
Distribution: Debian Sid (Kanotix)
Posts: 237

Original Poster
Rep: Reputation: 30
Thumbs up

Thanks gilead!

I understand now.
 
Old 11-23-2006, 06:17 PM   #5
rollo
Member
 
Registered: Apr 2004
Location: France
Distribution: Debian Sid (Kanotix)
Posts: 237

Original Poster
Rep: Reputation: 30
Smile

Thanks for the clarification, indynick.
 
Old 11-23-2006, 07:01 PM   #6
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Because many programs set the return status to 0 if they are successful (a notable exception being grep), it's common to see something like this in a script:
Code:
some_command || exit 3
which would cause the script to exit with it's own non-zero status. in this case 3.
 
Old 11-23-2006, 08:06 PM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Grep works.

For example:
grep 'urlpoop' stupidwebpage.html && echo 'Found the stupid word'

Will return 0 if the regex is found and the echo command will be run. If it isn't found, the echo command will be skipped.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 09:00 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM
Monthly Archiving Script... help with "date" & "cron" Supp0rtLinux Linux - Software 3 01-03-2003 09:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration