Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 08-05-2006, 05:42 AM   #1
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:

exec < $1
while read line;
        $line || echo "error" && break;
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:
exec < $1
while read line;
        $line || break;
it's work good.

and also this code:
exec < $1
while read line;

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

Rep: Reputation: 166Reputation: 166
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:
($line || echo "error") && break
But you want it to behave like:
$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.


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 > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:10 AM.

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