LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 08-05-2006, 05:42 AM   #1
nadavvin
Member
 
Registered: May 2006
Distribution: ubuntu
Posts: 109

Rep: Reputation: 21
What is wrong in the statement: $line || echo "error" && break;


I did a little script to execute commands:

Code:
#!/bin/bash
exec < $1
while read line;
do       
        $line || echo "error" && break;
done
The problem is that the loop break after the first time.

what is the problem?

if $line is work fine, it is not supposed to execute the right side of the OR gate.

if $line is failed, it's supposed to continue the echo "error" and this is should to return true and only then execute the break.

if I use:
Code:
#!/bin/bash
exec < $1
while read line;
do       
        $line || break;
done
it's work good.

and also this code:
Code:
#!/bin/bash
exec < $1
while read line;
do

        $line || !(echo "error") || break;
done
 
Old 08-05-2006, 06:25 AM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
Aren't both operators of equal precedence? If they are, it executes from left to right, evaluating the || first and if either one was true it does the &&, causing the break. In effect it acts like:
Code:
($line || echo "error") && break
But you want it to behave like:
Code:
$line || ( echo "error" && break)
Those brackets are only me trying to explain what is happening, I haven't checked whether you can group operations like that with them.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
kopete & msn => "password wrong" while it definitely isn't... why?? ungua Linux - Software 6 06-02-2011 06:59 AM
BASH: How to NOT echo to screen with "if echo $x | grep ".*"; then" eur0dad Programming 9 07-27-2006 03:14 PM
"NIM thread blocked" & "Deadman Switch (DMS) close to trigger" errors sosborne Linux - Networking 1 06-28-2006 03:07 PM
how mute sound from "Line In" at start up & when not needed learnmelinux Linux - General 8 03-07-2005 11:13 PM
Segmentation fault on toplevel = XtVaAppInitialize(&app, "Email", NULL, 0, &argc, cbranje Programming 0 02-19-2005 01:06 PM


All times are GMT -5. The time now is 08:39 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration