Subject: Re: Re: [ast-users] arithmetic evaluation and -X operators
--------
> Ok, that's what I was thinking. 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
>
> the -n "$list" can be substituted with ((list)) as long as the unset
> value of $list is set to 0 - but then the expression maps to:
>
> if (( $# > 1 )) && [[ -t 0 && -t 1 ]] || ((list)); then
>
> which could hardly be called a simplification. I was hoping for
> something like
>
> if (( list || $# > 1 && -t 0 && -t 1 )); then
>
> which is neater and presumably better by some abstract measure.
> I can see how -t would violate the C-like syntax of arithmetic
> expressions, but surely something can be used? a simple stat() function
> perhaps?
>
Rewrite
if [[ -n "$list" || ( $# -gt 1 && -t 0 && -t 1 ) ]]; then
as
((list)) || ( (($# > 1 )) && [[ -t 0 || -t 1 ]] )
or slightly more efficiently
((list)) || { (($# > 1)) && [[ -t 0 || -t 1 ]] ;}
With ksh93u, (the first beta should be available before july 1st),
you can define math functions. For example you could define the
isatty math function with
function .sh.math.isatty fd
{
.sh.value=0
[[ -t $fd ]] && .sh.value=1
}
and then you could write this as
(( list || ($#>0 && (isatty(0) || isatty(1))) ))
David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users