From owner-freebsd-questions Mon Mar 27 7:47: 4 2000 Delivered-To: freebsd-questions@freebsd.org Received: from mail.targetnet.com (mail.targetnet.com [207.245.246.3]) by hub.freebsd.org (Postfix) with ESMTP id E7F4737BAD7 for ; Mon, 27 Mar 2000 07:46:59 -0800 (PST) (envelope-from james@targetnet.com) Received: from james by mail.targetnet.com with local (Exim 3.02 #1) id 12Zbhz-000EVb-00; Mon, 27 Mar 2000 10:45:39 -0500 Date: Mon, 27 Mar 2000 10:45:39 -0500 From: James FitzGibbon To: J McKitrick Cc: questions@freebsd.org Subject: Re: writing scripts Message-ID: <20000327104539.A40393@targetnet.com> References: <20000327160911.C9691@dogma.freebsd-uk.eu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0pre1i In-Reply-To: <20000327160911.C9691@dogma.freebsd-uk.eu.org> Organization: Targetnet.com Inc. Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG * J McKitrick (jcm@freebsd-uk.eu.org) [000327 10:10]: > i'm still working on my script to change my .muttrc depending where > i'm ssh'ing from. I tried grepping for my isp in the output of 'who', > but grep produces a null output file even if it finds no results. SO > when i test for the existence of that file, it will always be there > after running grep. 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. > Is there a better way of detecting what machine i am telnetting in > from and thaen choosing the correct .muttrc? You could also do something fancy like: last -1 `id -un` | grep -q isp1 retval=$? if [ $retval -eq 0 ] then ... action for isp1 else last -1 `id -un` | grep -q isp2 retval=$? if [ $retval -eq 0 ] then ... action for isp2 fi fi > Also, right now the script cats the color settings onto the end of a > basic .muttrc. The problem is when i save aliases, they need to be > moved into the base file, otherwise changes get lost. Is there a > better way to do this? In my .muttrc, I use: source ~/.mutt.aliases set alias_file = ~/.mutt.aliases And that allows me to put the aliases wherever I want. -- j. James FitzGibbon james@targetnet.com Targetnet.com Inc. Voice/Fax +1 416 306-0466/0452 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message