Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   ArchLinux General Discussion (http://www.linux-archive.org/archlinux-general-discussion/)
-   -   for conditional checking when running in bash. (http://www.linux-archive.org/archlinux-general-discussion/393305-conditional-checking-when-running-bash.html)

Victor Lowther 06-30-2010 09:47 PM

for conditional checking when running in bash.
 
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="33[1;37;40m" # main text

C_OTHER="33[1;34;40m" # prefix & brackets
--
1.7.1

Thomas Bächler 06-30-2010 09:56 PM

for conditional checking when running in bash.
 
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.

Daenyth Blank 06-30-2010 10:01 PM

for conditional checking when running in bash.
 
On Wed, Jun 30, 2010 at 17:56, Thomas Bächler <thomas@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.


All times are GMT. The time now is 08:25 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.