Hi Andrew,
Relax.
I'm way overdue for changing my habit of using [[ ]] and replacing it
with use of (( )) where appropriate.
You're not. You will use both, and each has its own purpose.
For this exercise in particular, [[ ]] is sufficient.
But neither could be considered neat, clean or simpler to read than
the original. Generally my scripts never work hard enough to care
about microseconds of efficiency, so cleaner more readable code wins
nearly every time. Better efficiencies are to be had with algorithm
or paying attention to I/O in my kind of script.
The basic problem is one of complexity and clarity.
You're trying to combine three tests into one.
As usual, it would be good to know the context; what is
the problem you're trying to solve?
Without that knowledge, the best we can do is explain *what* we test
for, but not *why*. A bit of analysis and (re)naming of bits goes
a long way, though.
> My original expression was a bit more
> complex than this:
>
> if [[ -n "$list" || ( $# -gt 1 && -t 0 && -t 1 ) ]]; then
>
> Where list can be '' or 1
Note twe can have && both inside and outside the [[ ]] construct,
The above is more clearly expressed as either
[[ -n $list ]] || [[ $# -gt 1 && -t 0 && -t 1 ]]
or
[[ $# -gt 1 && -t 0 && -t 1 ]] || [[ -n $list ]]
Now that we have the || clause at the end, we can split the left hand
side in two:
[[ $# -gt 1 ]] && [[ -t 0 && -t 1 ]]
Now we can add a appropriately named function
interactive() { [[ -t 0 && -t 1 ]; }
and reduce some of the clutter:
interactive && [[ $# -gt 1 ]] || [[ -n $list ]]
We're still left with '$list' and if the only possible values
are '' or 1, I guess it is not properly named.
Is this a flag carrying the result of a previous test?
Henk
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users