Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Want to replace bash w zsh as system shell on Ubuntu



[just responding to a small portion]

On Tue, 2 Feb 2010, Frank Terbeck wrote:

> Joke de Buhr wrote:
> 
> > By the way what is this syntax actually: (( ${#foo} > 0 ))
> 
> Yes, which is exactly what I used in both of my mails:
> (( ${#matches} > 0 )) && ...
> (( ${#array} > 0 ))
> 

I think Joke de Buhr meant (paraphrasing) "What is this syntax exactly?"

See 'man zshall', heading 'ARITHMETIC EVALUATION', second paragraph.  
It's treated as an arithmetic expression, and the return value is true 
if non-zero.

I generally write:

(( $#matches )) && ...do-whatever

omitting the '> 0', since it's semantically equivalent for arrays AFAICT 
(can't have negative number of elements), and leaving out the braces 
(just on personal preference).

> > I would use a conditional expressions: [[ ${#foo} -gt 0 ]]
> > I only remember the syntax (( a = 4 + 3 )) as an alternative to let 
> > and a arithmetic evaluation like "print $((4+3))".
> 
> Well, until someone tells me whether (( .. )) or [[ .. ]] would be 
> preferable performance-wise (which probably doesn't make that much of 
> an impact) I'll keep using arithmetic expressions when it comes to 
> numbers.  I find that a) logical and b) arithmetic expressions have a 
> lot more features for handling numbers than [[ .. ]] type tests do. I 
> guess that's my personal preference.

Pretty sure the performance benefits of one versus the other are more 
than outweighed by the benefit(s) of clarity and/or personal preference.

-- 
Best,
Ben



Messages sorted by: Reverse Date, Date, Thread, Author