Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-20-2019, 09:36 AM   #16
Senior Member
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 1,771

Rep: Reputation: Disabled

Originally Posted by hazel View Post
OK. "&&" and "||" are boolean operators, aren't they? So how does that work if the exit codes from test and rm are just integers?
Slightly off-topic, but I have seen cases where some shells (Including bash) will just silently exit when using "&&" in some circumstances. It seems to be more common when using "set -e" and at the end of nested loops/conditionals (Adding a "echo" or another command at the end sometimes helps) and when used many times consecutively. On the other hand "||" doesn't seem to suffer from these problems nor does using more canonical test statements.

This can workaround it where the ":" is a no-op.

{ [ "${foo}" ] && bar; } || :
Or this.

 [ -z "${foo}" ] || bar
I have also not yet seen some shells like dash or mksh suffer from these problems.
Old 09-20-2019, 09:46 AM   #17
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,860

Rep: Reputation: 1344Reputation: 1344Reputation: 1344Reputation: 1344Reputation: 1344Reputation: 1344Reputation: 1344Reputation: 1344Reputation: 1344Reputation: 1344
Off: When I do this:
set -e
make all 2>&1 | tee log.make.all
it won't stop if 'make all' fails. Unless I use 'set -o pipefail' too. Which is bash-specific.
Old 09-20-2019, 07:43 PM   #18
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,508

Rep: Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811
Originally Posted by hazel View Post
I remember reading in some programming guide or other that it's bad practice to have multiple error codes for different kinds of errors because nobody wants to have to look them up.
So, best practice is to use the same error code for all kinds of errors, that way nobody will ever be able to tell the difference between errors? At least looking up error codes won't be needed.


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
if statement ignoring true/false and proceeding anyway. Goblin_C_Noob Programming 4 03-30-2008 09:56 AM
comparison is always true/false jubaitca Programming 20 11-05-2006 06:55 PM
true or false? alaios Programming 7 07-16-2005 10:54 AM
Return true or false if I have ping reply Menestrel Programming 4 11-29-2004 12:40 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:14 PM.

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