[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Our Most Precious Resource: Programmer Time (was Re: long term goals)



[ Herbert Xu writes ]
> Philip Brown <phil@bolthole.com> wrote:
> >   Similarly, replace
> >      if [ xxx ]
> >   with
> >      if [[ xxx ]]
> 
> >   The first is EXTERNAL. the second is built-in to POSIX-sh
> 
> Nope, the first one is built-in to all the shells that I know of.  While
> the second one is not defined by POSIX and not supported by ash.

lemme put it this way:

The POSIX compliant shell I get to work with most, is ksh.
ksh runs faster if you use [[]] over [].



#!/bin/ksh -p

count=10000
while [ $count -gt 0 ] ; do
        count=$(($count-1))
done

--------------------------------------------------

with []:

$ time ./test.ksh

real    0m1.030s
user    0m1.010s
sys     0m0.010s


with [[]]:



$ time ./test.ksh

real    0m0.854s
user    0m0.830s
sys     0m0.030s


So using [[]] is a good habit to get into.

(and yes, I did multiple runs of this. results were consistent)



Reply to: