Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Mar 2000 10:45:39 -0500
From:      James FitzGibbon <james@targetnet.com>
To:        J McKitrick <jcm@freebsd-uk.eu.org>
Cc:        questions@freebsd.org
Subject:   Re: writing scripts
Message-ID:  <20000327104539.A40393@targetnet.com>
In-Reply-To: <20000327160911.C9691@dogma.freebsd-uk.eu.org>
References:  <20000327160911.C9691@dogma.freebsd-uk.eu.org>

next in thread | previous in thread | raw e-mail | index | archive | help
* 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000327104539.A40393>