Date: Mon, 27 Mar 2000 17:40:23 +0100 From: J McKitrick <jcm@freebsd-uk.eu.org> To: James FitzGibbon <james@targetnet.com> Cc: questions@freebsd.org Subject: Re: writing scripts Message-ID: <20000327174023.C10268@dogma.freebsd-uk.eu.org> In-Reply-To: <20000327104539.A40393@targetnet.com>; from james@targetnet.com on Mon, Mar 27, 2000 at 10:45:39AM -0500 References: <20000327160911.C9691@dogma.freebsd-uk.eu.org> <20000327104539.A40393@targetnet.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Mar 27, 2000 at 10:45:39AM -0500, James FitzGibbon wrote: > A better way to accomplish this task is > > grep -q search_string input_file > retval=$? > if [ $retval -eq 0 ] > then > ... actions if found > else > ... actions if not found > fi > > -q makes grep not produce output but exit with an error value based on > whether the search string was found (0 if it was, something else if it was > not). The assignment of $? (the error value) to 'retval' is not technically > required, but since $? changes with every external command that is run, it > is a common mistake to insert commands between the grep and the test, thus > changing the context of the test. Assiging the error value to retval right > after running the command preserves the value for later use. > Perfect! That's just what i needed. I changed some of the test conditions a little, but i think it will work. I'lll let you know when i telnet in from the other box. Actuially, is there a way to tell whether the computer running telnet or ssh is running windows or BSD? That's really an even better condition. The BSD xterm and the tera-term terminal both have different characteristics for showing color. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000327174023.C10268>