Re: shell script question

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Jerry Davis
Date:  
To: Main PLUG discussion list
CC: plug-discuss
Subject: Re: shell script question
On Mon, 31 Jul 2006 14:51:41 -0700
Kurt Granroth <> wrote:

> Yep, that's exactly what it's doing. You typically don't want to do
> a kill on a process if you don't have a process id... hence the check
> if it's empty.
>
> Why, then, doesn't it just do this?
>
> if [ "$pid" != "" ]
>
> Well, this takes me back a bit so my memory might not be 100%
> accurate here. Say $pid is empty, though. What this would look like
> is:
>
> if [ "" != "" ]
>
> Modern shells can handle this just fine. Older shells (like the
> original Bourne shell) got confused by this. So as a matter of
> practice, you would put a guaranteed non-NULL character in both sides
> of the string. If the environment variable was null, then it would
> look like so:
>
> if [ "X" != "X" ];
>
> which is the same as "" != "".
>
> As I said, though, it's been a while since I learned to do that so my
> memory could be shot.


no. your memory is just fine.
I remember having to do this even on newer shells like ksh on some
other systems like HPUX. Linux would handle things fine. HPUX vs. AIX
vs linux can trip you up.

in bash I think you can do if [ -z $var ] and that will do it too.

Jerry

>
> On Monday 31 July 2006 14:36, David wrote:
> > What is the point of the below in a script? This snippage is in the
> > 'stop' portion of an init script. I just dont see the point of the
> > if statement. It almost looks like it's just making sure $pid isn't
> > empty.
> >
> >
> > ------begin snippet------
> >
> > pid=`/bin/ps -e | grep process_name | grep -v mon | grep -v grep |
> > sed -e 's/^  *//' -e 's/ .*//' | head -1`
> >      if [ "X$pid" != "X" ]
> >      then
> >              /bin/kill $pid
> >              echo "**process_name** interface stopped"
> >      fi
> > ------end snippet------

> >
> > Thanks,
> > David
> ---------------------------------------------------
> PLUG-discuss mailing list -
> To subscribe, unsubscribe, or to change you mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss



--
Happy Trails!

Hobbit Name: Pimpernel Loamsdown
Registered Linux User: 275424

This email's random fortune: "Engineering meets art in the parking lot
and things explode."
-- Garry Peterson, about Survival Research Labs
---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss