Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Want to replace bash w zsh as system shell on Ubuntu
- X-seq: zsh-users 14777
- From: "Benjamin R. Haskell" <zsh@xxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Want to replace bash w zsh as system shell on Ubuntu
- Date: Tue, 2 Feb 2010 16:11:29 -0500 (EST)
- In-reply-to: <87bpg7jscq.fsf@xxxxxxxxxxxxxxxxxxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20100202081546.GA5930@xxxxxxxxx> <201002021928.20601.joke@xxxxxxxxx> <87fx5jjw7m.fsf@xxxxxxxxxxxxxxxxxxxxxx> <201002022029.06336.joke@xxxxxxxxx> <87bpg7jscq.fsf@xxxxxxxxxxxxxxxxxxxxxx>
[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