On 7/10/11 6:33 PM, Linda Walsh wrote: > > > Andreas Schwab wrote: > >> Linda Walsh <b...@tlinx.org> writes: >> >>> if [[ -z "" && ((LINES < 80 )) ]]; then echo foo; fi >>> (prints nothing).... >>> >>> What am I missing? >> >> "LINES" does not sort before "80". >> >> Andreas. >> > > But it compares == to 66?
As always, Andreas is the soul of brevity. What he means is that the conditional expression operators </=/> perform string comparisons. If you want arithmetic comparisons, you still have to use -le, -eq, and -gt. > > Normally, in the shell, if you type in something in double parens > it does a mathematical evaluation. When you're in a place where you can enter a command name, (( ... )) will perform arithmetic evaluation equivalent to let "...". A conditional expression is not such a place. > i.e. > if you are in a while loop ...and entering a command. > so I'd expect the above to eval my shell-var, 'lines'... > Ah....I see....I need another set of parens!... > (ARG....!!.... > What rule should I have remembered to 'know' that? The rule you need is in the manual. In a conditional expression parens only serve to override normal operator precedence. Adding extra pairs of parens doesn't do anything special. > 'if in [[ ]], then you need an extra level of parens around a double-paren > expression to get mathematical evaluation'... This is pretty much nonsense. The operators and their precedence are in the manual under CONDITIONAL EXPRESSIONS. If you want an arithmetic comparison, use one of the arithmetic comparison operators. If you want the operands to those operators to undergo arithmetic expansion, use the standard $((...)) word expansion. > I guess many of us are still learning about these things as they unfold -- > and of course Chet keeps ahead of us by continually throwing in more > benefits... This hasn't changed in years. The -lt/-eq/-gt operators were inherited from test and are archaic. Since you want to mix conditional and arithmetic comparisons, you might consider using something like if [[ -z "" ]] && (( LINES < 80 )); then foo fi Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/