Re: shell script question

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Kurt Granroth
Date:  
To: plug-discuss
Subject: Re: shell script question
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.

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