LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

Rep: Reputation: Disabled

Quote:
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.

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

Code:
 [ -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
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,862

Rep: Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347
Off: When I do this:
Code:
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
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,509

Rep: Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811Reputation: 1811
Quote:
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.
 
  


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
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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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