LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 05-08-2019, 12:43 PM   #1
AnneRanch
Member
 
Registered: Oct 2018
Posts: 198

Rep: Reputation: 12
Evaluating variables in bash - vent


After couple of years scripting (in bash) I have to ask.
Finally got used to looking at bash "variables" as characters / strings.
About same time I realized that Linux is Unix based and recalled having hard time accepting NO response when Unix command completed successfully.

Yes, I am that old to remember that TTY was pretty slow and NO or minimal response was just memory / time saver.

So - taking BOTH into account - if CORRECT response is NUMERICAL zero, why do some "coders" use "set=yes" to complicate such simple task as evaluation ?

I am not sure where I encountered a discussion about "test" evaluating for "empty string" as opposed for "undefined string". Maybe that is the reason for replacing 0/1 test with "yes/no".
Just venting.
Cheers
 
Old 05-08-2019, 01:04 PM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 12,590

Rep: Reputation: 3930Reputation: 3930Reputation: 3930Reputation: 3930Reputation: 3930Reputation: 3930Reputation: 3930Reputation: 3930Reputation: 3930Reputation: 3930Reputation: 3930
would be nice to show us some examples.
bash has variables, but these variables have no type (so they can be integers and strings too). bash has no real arithmetic (just some minimal functionality implemented), so it is not really useful.
 
Old 05-08-2019, 01:32 PM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 5,064
Blog Entries: 11

Rep: Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008
Quote:
Originally Posted by AnneRanch View Post
After couple of years scripting (in bash) I have to ask.
Finally got used to looking at bash "variables" as characters / strings.
About same time I realized that Linux is Unix based and recalled having hard time accepting NO response when Unix command completed successfully.

Yes, I am that old to remember that TTY was pretty slow and NO or minimal response was just memory / time saver.

So - taking BOTH into account - if CORRECT response is NUMERICAL zero, why do some "coders" use "set=yes" to complicate such simple task as evaluation ?

I am not sure where I encountered a discussion about "test" evaluating for "empty string" as opposed for "undefined string". Maybe that is the reason for replacing 0/1 test with "yes/no".
Just venting.
Cheers
That is very vague.

Without an example it is not possible for anyone here to guess why other coders may or may not do some thing, or guess the nature of a discussion you cannot yourself remember.

Please review the Site FAQ for guidance in asking well formed questions.

If you wish to amend your post to meet that general standard then please do so. Otherwise the thread may be moved to the General forum which is more appropriate for vents and rants.

Last edited by astrogeek; 05-08-2019 at 01:37 PM. Reason: Added OP quote for completeness
 
Old 05-08-2019, 03:36 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,667
Blog Entries: 15

Rep: Reputation: 1578Reputation: 1578Reputation: 1578Reputation: 1578Reputation: 1578Reputation: 1578Reputation: 1578Reputation: 1578Reputation: 1578Reputation: 1578Reputation: 1578
Quote:
After couple of years scripting (in bash) I have to ask.
There are multiple languages available if you don't like bash. Perl, Ruby, Python, PHP and of course you can write your own C code and compile it.

Quote:
About same time I realized that Linux is Unix based
Technically incorrect. Linux is a clone of UNIX written from scratch. It is not derived from UNIX source. Being an old UNIX admin myself I can tell you in general even though many commands have the same name the GNU/Linux/FOSS versions invariably have more functionality.

Quote:
recalled having hard time accepting NO response when Unix command completed successfully.
Every command gives return codes even if they don't output anything visible. If you want confirmation the command worked checked to see if its return code is 0. Non-zero return codes are defined by the applications so don't always indicate "error" but most do.


Quote:
Yes, I am that old to remember that TTY was pretty slow and NO or minimal response was just memory / time saver.
I'm fairly old as well. Linux (like UNIX) allows you to background things so TTYs aren't required. As others have noted you'd have to give examples for anyone to know what your talking about.

Quote:
why do some "coders" use "set=yes" to complicate such simple task as evaluation
For the same reason some people drive smart cars and others drive Hummers. Personal preference.
FOSS by its very nature encourages people to do things the way they want and if someone finds they don't like another's way they are free to modify the source code to do it the way they want.

Mailing lists and discussion boards are full of opinions and sometimes the discussions are quite heated. Feel free to vent away but don't be surprised if people counter-vent.
 
Old 05-08-2019, 05:21 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,441

Rep: Reputation: 1702Reputation: 1702Reputation: 1702Reputation: 1702Reputation: 1702Reputation: 1702Reputation: 1702Reputation: 1702Reputation: 1702Reputation: 1702Reputation: 1702
Quote:
Originally Posted by AnneRanch View Post
So - taking BOTH into account - if CORRECT response is NUMERICAL zero, why do some "coders" use "set=yes" to complicate such simple task as evaluation ?
(NOTE: The following is speculation, I don't know the actual historical reasons.) Using "0" to mean yes is confusing, because the natural interpretation is 0=no, 1=yes. Furthermore, you can't save a bash exit status inside a variable, it's not a first class value. You can save the string "0", then you have compare with test $foo = 0 to reinstate the 0 exit status, so you can see that this doesn't actually save any complication. May as well use test $foo = yes and avoid the possible confusion over 0/1.
 
Old 05-08-2019, 06:06 PM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 5,064
Blog Entries: 11

Rep: Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008Reputation: 3008
Moved: This thread is more suitable in the General forum and has been moved accordingly.
 
Old 05-08-2019, 06:44 PM   #7
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 7,635
Blog Entries: 13

Rep: Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158
Answer #1: All of this is very easily settled by writing a test script, echoing out some of these variables, and turning on shell debug.

Pretty much many members of LQ are experienced and similarly have used Unix.

The problem here is your vent is misplaced if this is all that you have to say.

Firm Answer: I'd be glad to inspect a small bash script and offer my thoughts on why tests obtain a certain result.

Blocking Point: For now, you have shown zero code in support of your rant and instead told us all about how you have experience. Great! But those of well rounded experience also know that they don't know everything, myself included, and thus when we ask a question, we do so, but also support it in some technical manner. If our way of thinking is absolutely skewed, one or more response givers will point out the flaws in our logic and, for myself, I'd be glad to understand where my thinking was incorrect.

That is the old, "You learn something everyday", mantra.

I can say for certain that there are inadvisable coding practices that I see in source code as well as in scripts. One of them is a true/false assumption for command results. An example is grep. It returns zero for success, 1 for nothing found, and 2 if there was an actual error in the command. The distinctions are important, and by reviewing the manual page for grep, one can see this for their self.
 
Old 05-09-2019, 12:44 AM   #8
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 11,450
Blog Entries: 8

Rep: Reputation: 2989Reputation: 2989Reputation: 2989Reputation: 2989Reputation: 2989Reputation: 2989Reputation: 2989Reputation: 2989Reputation: 2989Reputation: 2989Reputation: 2989
Quote:
There are multiple languages available if you don't like bash.
there are also multiple shells available if you don't like bash.
but i doubt any one of them would use 1 for true and 0 for false...
 
  


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
[SOLVED] BASH: Evaluating variable, in while loop bspears1 Programming 9 12-19-2012 10:18 AM
[bash] expression is always evaluating to true fakie_flip Programming 11 06-09-2011 08:16 AM
[SOLVED] [bash] dynamiquely evaluating variable names oukourj Programming 7 06-07-2011 01:20 AM
[SOLVED] Evaluating bash script without saving - help! igadoter Programming 5 09-05-2010 05:32 PM
Vent Server problem Ghettozn Linux - Newbie 3 08-02-2003 02:57 PM

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

All times are GMT -5. The time now is 06:27 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