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 14774
- From: Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>
- To: Joke de Buhr <joke@xxxxxxxxx>
- Subject: Re: Want to replace bash w zsh as system shell on Ubuntu
- Date: Tue, 02 Feb 2010 20:04:13 +0100
- Cc: zsh-users@xxxxxxx
- In-reply-to: <201002021928.20601.joke@xxxxxxxxx> (Joke de Buhr's message of "Tue, 2 Feb 2010 19:28:20 +0100")
- 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> <201002021806.25016.joke@xxxxxxxxx> <87mxzrjzkv.fsf@xxxxxxxxxxxxxxxxxxxxxx> <201002021928.20601.joke@xxxxxxxxx>
Joke de Buhr wrote:
> On Tuesday 02 February 2010 18:51:28 Frank Terbeck wrote:
[...]
>> > matches=("$HOME"/((.*|*)/)#*(#q^u${SUDO_UID}u${UID},^g${SUDO_GID}g${GID})
>> >) [[ -n ${matches} ]] && chown $SUDO_UID:$SUDO_GID "${matches[@]}"
>>
>> (( ${#matches} > 0 )) && ...
>>
>
> [[ -n ${matches} ]] only needs to check if the array "matches" is not empty
> (( ${#matches} > 0 )) needs to calculate the length of the array and compare
> if the result is > 0. I think [[ -n ${matches} ]] will be more efficient.
I wouldn't bet on that.
I'm not sure how arrays are implemented internally. But I could imagine
the number of elements is kept somewhere and therefore is available
without additional effort (can somebody confirm this?).
Also, I'm not sure what happens exactly, when you do [[ -n $array ]].
Say, $array is ( foo bar baz ). If you now do [[ -n $array ]], what
happens?
a) Does it get expanded to [[ -n "foo bar baz" ]]?
b) Does it get expanded to [[ -n "foo" "bar" "baz" ]]?
If a), zsh would have to create a string from the array in which case
looking at the number of elements is certainly quicker.
If b), what happens if the first entry of the array is an empty string?
Maybe it's even neither of the two and zsh does something smart when an
array is used in a [[ ... ]] style test.
Since I really don't know what it does, I just try:
[snip]
zsh% foo=( foo bar baz )
zsh% set -x; [[ -n $foo ]]; set +x
+/bin/zsh:234> [[ -n 'foo bar baz' ]]
+/bin/zsh:234> set +x
[snap]
Seems like it concatenates the elements into a string. So I think my
(( ${#array} > 0 ))
approach would win in a benchmark. Unless I'm missing some smart trick
that zsh may use to optimise this.
Regards, Frank
Messages sorted by:
Reverse Date,
Date,
Thread,
Author