[arch-general] [PATCH 04/48] Use [[ ]] instead of [ ] for conditional checking when running in bash.

2010-06-30 Thread Victor Lowther
It is worth 10 - 30% speedup whenever you want to compare something.
---
 functions |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/functions b/functions
index 6df8c5e..9b348b7 100644
--- a/functions
+++ b/functions
@@ -40,7 +40,7 @@ unset TERM_COLORS
 unset TZ
 
 # colors:
-if [ $USECOLOR = YES -o $USECOLOR = yes ]; then
+if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then
C_MAIN=\033[1;37;40m  # main text
 
C_OTHER=\033[1;34;40m # prefix  brackets
-- 
1.7.1



Re: [arch-general] [PATCH 04/48] Use [[ ]] instead of [ ] for conditional checking when running in bash.

2010-06-30 Thread Thomas Bächler
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?

 -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.



signature.asc
Description: OpenPGP digital signature


Re: [arch-general] [PATCH 04/48] Use [[ ]] instead of [ ] for conditional checking when running in bash.

2010-06-30 Thread Daenyth Blank
On Wed, Jun 30, 2010 at 17:56, Thomas Bächler tho...@archlinux.org 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?

 -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.



Quoting is not needed in [[ and it makes the code uglier.


Re: [arch-general] [PATCH 04/48] Use [[ ]] instead of [ ] for conditional checking when running in bash.

2010-06-30 Thread 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.

-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] [PATCH 04/48] Use [[ ]] instead of [ ] for conditional checking when running in bash.

2010-06-30 Thread bardo
2010/7/1 Daenyth Blank daenyth+a...@gmail.com:
 On Wed, Jun 30, 2010 at 17:56, Thomas Bächler tho...@archlinux.org 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?

 -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.



 Quoting is not needed in [[ and it makes the code uglier.


Ditto. May I also suggest a link[1] to those that do not know all the
beauties of double square brackets? By the way, the whole BashFAQ in
there is really interesting, it has lots of advanced tips 'n tricks.

Corrado


[1] http://mywiki.wooledge.org/BashFAQ/031


Re: [arch-general] [PATCH 04/48] Use [[ ]] instead of [ ] for conditional checking when running in bash.

2010-06-30 Thread Thomas Bächler
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.



signature.asc
Description: OpenPGP digital signature


Re: [arch-general] [PATCH 04/48] Use [[ ]] instead of [ ] for conditional checking when running in bash.

2010-06-30 Thread Victor Lowther
On Thu, 2010-07-01 at 00:24 +0200, bardo wrote:
 2010/7/1 Daenyth Blank daenyth+a...@gmail.com:
  On Wed, Jun 30, 2010 at 17:56, Thomas Bächler tho...@archlinux.org 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?
 
  -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.
 
 
 
  Quoting is not needed in [[ and it makes the code uglier.
 
 
 Ditto. May I also suggest a link[1] to those that do not know all the
 beauties of double square brackets? By the way, the whole BashFAQ in
 there is really interesting, it has lots of advanced tips 'n tricks.
 
 Corrado
 
 
 [1] http://mywiki.wooledge.org/BashFAQ/031

greycat and friends are awesome, it is true.  I learned alot reading
gregs wiki and hanging out on #bash.

-- 
Victor Lowther
LPIC2 UCP RHCE