Skip to content

bash export is lacking Boolean expression handling #1208

@codemanyak

Description

@codemanyak
Image

The red instruction at the end of the diagram shows that there is still no sensible solution for boolean expressions at hand.

Originally posted by @codemanyak in #1207

The bash generator has no strategy so far for the export of Boolean variables (assignment of Boolean expression results), Boolean routine arguments and the output of Boolean values.
Indeed, it's difficult since shells transfer test results as process status. So they can neither be stored nor printed directly.
In the above example, neither

echo $(( a < 23 ))

nor

echo (( ${a} < 23 ))

would be any better. Even if no syntax error were reported, the comparison result would never occur in the output stream. Something like the following would work instead:

if (( ${a} < 23 )) ; then echo TRUE ; else echo FALSE ; fi

To store or transfer Boolean values certain numeric values (e.g. 0 for true and all else for false like the process status, or other way round) or string values (e.g. "TRUE" and "FALSE") must be used as surrogate. This would suggest the provisioning with two complementary shell functions (or notations) for the produced code - one to derive the respective surrogate values from a test result (might be named bool) to be used for assignment, parameter passing, or output - and the other one to succeed or fail according to a comparison of the argument variable with the surrogate values (might be named testbool or isTrue) to be used when Boolean variables are involved in conditions.
For a halfway consistent solution for bash export in this sense, however, an expression representation as syntax tree together with robust static type inference is a prerequisite, such that this issue is related to the complete code revision according to #800.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions