KSH if-then v. [[ ]] && || notation and relative speed of equivalent command constructs
DaviD W. Sanderson
dws at margay.cs.wisc.edu
Wed Apr 17 03:26:15 AEST 1991
In article <1991Apr15.165925.26321 at ux1.cso.uiuc.edu> jeffo at uiuc.edu writes:
>In KSH, which is faster:
>
>if [[ ${a} = 5 ]] then print 'a is set to 5'
>else print 'a is not set to 5'
>...or...
>[[ ${a} = 5 ]] && print 'a is set to 5' || print 'a is not set to 5'
I would guess these are about the same (I don't know for sure).
In this specific instance both are left in the dust by
case $a
{
5) print 'a is set to 5'
;;
*) print 'a is not set to 5'
;;
}
A general rule is that it is fastest to use "case" when all you want to
do is pattern matching. Note that the $a is implicitly quoted in the
case syntax, so it doesn't matter if it contains white space. It is
superflous to use
case "$a"
Other supposedly sh-compatible shells may not do this implicit quoting.
--
___
/ __\ U N S H I N E DaviD W. Sanderson
| | | I N E dws at cs.wisc.edu
_____| | |_____ ________
\ / \ |__/ /////__ Fusion Powered Locomotives Made to Order
\____/ \__|_/ \\\\\______ (TARDIS model available at extra cost)
More information about the Comp.unix.shell
mailing list