Re: TRUE is 0 is FALSE
- From: Janis Papanagnou <janis_papanagnou@xxxxxxxxxxx>
- Date: Thu, 20 Oct 2011 11:01:39 +0200
Am 19.10.2011 17:39, schrieb Kaz Kylheku:
On 2011-10-19, Janis Papanagnou<janis_papanagnou@xxxxxxxxxxx> wrote:What you have presented (suggested?), to me, doesn't seem to solve
anything, rather just complicates matter. The existing exit-status
bool concept in standard shell seems conceptually clear and effective.
An explicit literal - in string form - for boolean values don't seem
necessary, neither seems a boolean type based on a string type to be
a good idea. YMMV, of course.
The premise of this discussion, as I understood it, is that shell scripts
sometimes store boolean values in variables. That being accepted, what is the
best practice for doing it?
I suspect you may be responding to the examples, for which there exists
equivalent simpler code that does not store a boolean in a variable.
What is your recommendation for representing boolean conditions as data? How
would you capture the success/fail termination status of a command pipe and
store that in a variable? How would you turn the contents of a boolean variable
into a termination status for a function or script?
Typically, in shell, I use a [quasi-]numeric plain flag. (Some shells
store that as string, other shells as integer.) I usually use ksh and
there's the ((...)) construct (in addition to the $((...)) expansion)
where such flags - or, more generally, expressions - will be converted
to a success status.[*] A quite concise, consistent, and clear concept.
Beyond what I've written and WRT "store in a variable", I can only say
that there's the $? built-in variable for commands, which I rarely had
the need to use, though, in favour of the clearer constructs to put the
commands directly in the if/while/... conditions. WRT the status of a
pipeline; it will reflect the exit status of the last command in the
pipeline (I presume this is standard?) so that you can write a pipeline
as well directly in some conditional control constructs. If you meant
that some intermediate process can fail, that's an entirely different
issue with it's own problems; the prominent shells support some form
of pipestatus information or handling of failure cases (PIPESTATUS -
in whatever format they store it -, or pipefail).
Janis
[*] Current bash and zsh seem to support that as well.
.
- Follow-Ups:
- Re: TRUE is 0 is FALSE
- From: Kaz Kylheku
- Re: TRUE is 0 is FALSE
- References:
- Re: TRUE is 0 is FALSE
- From: Kaz Kylheku
- Re: TRUE is 0 is FALSE
- From: Seebs
- Re: TRUE is 0 is FALSE
- From: Janis Papanagnou
- Re: TRUE is 0 is FALSE
- From: Kaz Kylheku
- Re: TRUE is 0 is FALSE
- From: Janis Papanagnou
- Re: TRUE is 0 is FALSE
- From: Kaz Kylheku
- Re: TRUE is 0 is FALSE
- Prev by Date: Re: awk help!
- Next by Date: [META] [OT] Re: plsql: for loop text variable
- Previous by thread: Re: TRUE is 0 is FALSE
- Next by thread: Re: TRUE is 0 is FALSE
- Index(es):
Relevant Pages
|