Re: TRUE is 0 is FALSE



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



Relevant Pages

  • Re: dried pasta as horse treat?
    ... Ruffian wrote: ... the crunch reverberating around in their large sinuses is amusing. ... cheap, easy to store, durable treat. ... Jessica even used pasta "shells" as an example. ...
    (rec.equestrian)
  • Re: How to work with multiple response sets in Access
    ... simple checkboxes. ... but it gets simpler if I have only one survey ... and a table to store each answer to each question for each survey ... store the values in a Boolean field in the answers table, ...
    (microsoft.public.access.tablesdbdesign)
  • Re: stuffed shells?
    ... make stuffed shells all the time pre-diabetes. ... particular store doesn't stock them. ... foods that don't sell in a particular hood. ...
    (rec.food.cooking)
  • Re: stuffed shells?
    ... make stuffed shells all the time pre-diabetes. ... I wager nobody ever even heard of pasta let alone pasta shells. ... I think these days most people in this country eat Italian food. ... delivered to me once from a local store. ...
    (rec.food.cooking)
  • Re: Crash saving boolean value to RS (Row cannot be located...)
    ... Brendan Reynolds ... > Close RecordSet ... > The issue I'm dealing with is that I was attempting to store the Gender ... >> What if you give the Boolean field a default value. ...
    (microsoft.public.data.ado)