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 |
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. |
Quote:
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. |
Quote:
Quote:
Quote:
Quote:
Quote:
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. |
Quote:
|
Moved: This thread is more suitable in the General forum and has been moved accordingly.
|
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. |
Quote:
but i doubt any one of them would use 1 for true and 0 for false... |
All times are GMT -5. The time now is 02:31 PM. |