LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-09-2009, 03:00 PM   #1
Al Effendi
LQ Newbie
 
Registered: Dec 2003
Posts: 8

Rep: Reputation: 0
|| && problem


hi
thanks in advance

$ command1 || command2 || command3 || command4
I know This line of code will not run the next command in the sequence unless the prior command has returned "false" i.e. 1

BUT I cannot understand the foll.
(( 200 || 11 )) # Logical OR
echo $?
# answer 1

why?
what do 200, 11 represent ?

Or for that matter
if ( ( 1 && 2 ) || ! 3 ) then
echo TRUE
else


# answer TRUE

why?
what do 1,2,3 represent ?

appreciate help
 
Old 11-09-2009, 06:18 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Plenty of detail here:
http://www.faqs.org/docs/abs/HTML/tests.html
http://www.faqs.org/docs/abs/HTML/dblparens.html

..let us know if you still need assistance

cheers
 
Old 11-09-2009, 11:22 PM   #3
Al Effendi
LQ Newbie
 
Registered: Dec 2003
Posts: 8

Original Poster
Rep: Reputation: 0
hi
thanks all
yes I still need assistance. I can understand if the above commands were like ls nosuchfile or dir nosuchfile but numbers ?
 
Old 11-10-2009, 12:20 AM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Do you have a script that uses one of these constructs ? .. they appear to be incorrectly used

thanks
 
Old 11-10-2009, 01:54 AM   #5
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Going by http://www.faqs.org/docs/abs/HTML/dblparens.html, the code with numbers is interpreted as C code.
In C language, any non-zero number is regarded as logical true, zero being logical false.
So:
Code:
(( 200 || 11 )) == true OR true == true (result = 1)
(( 1 && 2 ) || ! 3 ) == ((true AND true) OR !true) == ( true OR false ) == true
Needless to say, the constructs are a bit strange, and even make me think of homework on boolean algebra...

I suggest you read up on the double paranthesis (( )) operator, which is used for C-style arithmetic operations.
Not to be confused with logical operators that link together commands, nor with bitwise logic.
 
Old 11-11-2009, 01:28 PM   #6
Al Effendi
LQ Newbie
 
Registered: Dec 2003
Posts: 8

Original Poster
Rep: Reputation: 0
kbp timmeke THANKS || && problem got it to anyone I missed my apologies Al Effendi

Al Effendi
 
Old 11-11-2009, 03:12 PM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Al_Effendi;

I merged your last post into this thread----it appears you intended to answer here (but you started a new thread.)

Good luck
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
zsnes && logitech dual action gamepad && dpad woes John5788 Linux - Games 5 10-29-2008 09:56 PM
AOL UK && BT Voyager 100 && Slackware 10.2 && RP-PPPoE pitt0071 Linux - Networking 3 01-17-2006 06:10 AM
(FreeBSD && Fedora Core 4 && Slackware 10.0) Filesystem Support taylor_venable *BSD 1 07-14-2005 02:24 PM
Japanese canna won't work : Warning: かな漢字変&am OrganicOrange84 Debian 3 06-30-2005 02:28 PM
Phục hồi dữ liệu bị mất???, cứ pollsite General 1 06-27-2005 12:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:03 AM.

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