Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!uwm.edu!uwvax!margay.cs.wisc.edu!dws From: dws@margay.cs.wisc.edu (DaviD W. Sanderson) Newsgroups: comp.unix.shell Subject: Re: KSH if-then v. [[ ]] && || notation and relative speed of equivalent command constructs Keywords: KSH [[..]] && || if-then notation faster Message-ID: <1991Apr16.172615.15512@spool.cs.wisc.edu> Date: 16 Apr 91 17:26:15 GMT References: <1991Apr15.165925.26321@ux1.cso.uiuc.edu> Sender: news@spool.cs.wisc.edu (The News) Organization: U of Wisconsin CS Dept Lines: 34 Originator: dws@margay.cs.wisc.edu In article <1991Apr15.165925.26321@ux1.cso.uiuc.edu> jeffo@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@cs.wisc.edu _____| | |_____ ________ \ / \ |__/ /////__ Fusion Powered Locomotives Made to Order \____/ \__|_/ \\\\\______ (TARDIS model available at extra cost)