From owner-freebsd-questions Mon Mar 27 8:40:59 2000 Delivered-To: freebsd-questions@freebsd.org Received: from probity.mcc.ac.uk (probity.mcc.ac.uk [130.88.200.94]) by hub.freebsd.org (Postfix) with ESMTP id 136B537B625 for ; Mon, 27 Mar 2000 08:40:29 -0800 (PST) (envelope-from jcm@dogma.freebsd-uk.eu.org) Received: from dogma.freebsd-uk.eu.org ([130.88.200.97]) by probity.mcc.ac.uk with esmtp (Exim 1.92 #3) id 12ZcYx-000Pqx-00; Mon, 27 Mar 2000 17:40:23 +0100 Received: (from jcm@localhost) by dogma.freebsd-uk.eu.org (8.9.3/8.9.3) id RAA10462; Mon, 27 Mar 2000 17:40:23 +0100 (BST) (envelope-from jcm) Date: Mon, 27 Mar 2000 17:40:23 +0100 From: J McKitrick To: James FitzGibbon Cc: questions@freebsd.org Subject: Re: writing scripts Message-ID: <20000327174023.C10268@dogma.freebsd-uk.eu.org> References: <20000327160911.C9691@dogma.freebsd-uk.eu.org> <20000327104539.A40393@targetnet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i In-Reply-To: <20000327104539.A40393@targetnet.com>; from james@targetnet.com on Mon, Mar 27, 2000 at 10:45:39AM -0500 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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