Xref: utzoo alt.sources:155 comp.os.minix:2557 Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!pasteur!fraud.Berkeley.EDU!sarge From: sarge@fraud.Berkeley.EDU (Steven Sargent) Newsgroups: alt.sources,comp.os.minix Subject: Re: Public Domain version of: yes(1) Message-ID: <2211@pasteur.Berkeley.Edu> Date: 8 Apr 88 17:57:15 GMT References: <310@rolls.UUCP> <4571@chinet.UUCP> Sender: news@pasteur.Berkeley.Edu Reply-To: sarge@scam.berkeley.edu Organization: Experimental Shell-script Facility, Berkeley CA Lines: 52 Keywords: Free Software > If you look closely, you'll see that you are doing a comparision on each > > if [ "$#" -gt 1 ] > then > ans=$* > else > ans=y > fi > while true > do > echo $ans > done > > Check what you want to echo ONCE ONLY, assign it and echo it. Why not? 1. It's wrong -- doesn't implement the spec (4bsd manual page) in two ways: it should only echo $1, not $*; also, you should use -ge, not -gt. 2. Any puny performance advantage you might get from doing the test only once is completely swamped by the exec penalty on true, once per loop. Benchmark your version against *** cut here #!/bin/sh while :; do echo ${1-y} done *** end Recall that ${1-y} is built into the shell. test may or may not be (it isn't on 4bsd; is in V.3). : also is built-in. If you need more complicated stuff than $ provides, "case" covers a lot of situations, again without exec. The manual page gives much cryptic info here. 3. (careful, big words coming up) Your adding the spurious temporary variable "ans" breaks an otherwise referentially transparent program; the fact that doing so confers no compensating performance advantage is all the worse. > I have watched all of these varieties of yes(1) come whizzing by, and > must wonder: Are you all all that bad? "We all" may be hurling a lot of cement pies your way; maybe you should leave town for awhile? Steven "Trust but verify" Sargent. --- "I'm sorry... you must have me confused with some other plate-lipped white girl named Irene." -- Good Girls #2 Steven Sargent ARPA Internet: sarge@scam.berkeley.edu MILnet: sarge%scam.berkeley.edu@ucbvax.berkeley.edu TPCnet: {anywhere at all, really}!ucbvax!scam!sarge