[arch-general] [PATCH 04/48] Use [[ ]] instead of [ ] for conditional checking when running in bash.
Thomas Bächler
thomas at archlinux.org
Wed Jun 30 18:29:59 EDT 2010
Am 01.07.2010 00:22, schrieb Victor Lowther:
> On Wed, 2010-06-30 at 23:56 +0200, Thomas Bächler wrote:
>> Am 30.06.2010 23:47, schrieb Victor Lowther:
>>> It is worth 10 - 30% speedup whenever you want to compare something.
>>
>> Where do you get this from? I always used [ ], and I found it
>> sufficient. Why is [[ ]] faster?
>
> [[ ]] is faster because it is bash syntax, not a builtin command like
> [ is. In most programs, both are fast enough, but you an see the
> difference if you run otherwise identical tests in a loop one million
> times.
>
>>
>>> -if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then
>>> +if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then
>>
>> Why do you get rid of the quoting here? Quoting is nice.
>
> Because [[ ]] is bash syntax instead if a builtin comand, it relaxes the
> usual expansion rules -- inside of [[ ]], word splitting and pathname
> expansion are not performed, so you only have to quote strings if they
> need to be single-quoted.
> http://wiki.bash-hackers.org/syntax/ccmd/conditional_expression has more
> info.
>
Sounds nice. This will probably mean that I will apply all the patches
that do this transition - however, it might probably be nicer to squash
all of those into one commit.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://mailman.archlinux.org/pipermail/arch-general/attachments/20100701/a77d8d24/attachment.bin>
More information about the arch-general
mailing list