Complete.Org: Mailing Lists: Archives: discussion: March 2000:
[aclug-L] Re: script to kill

[aclug-L] Re: script to kill

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: discussion@xxxxxxxxx
Subject: [aclug-L] Re: script to kill
From: Carl D Cravens <raven@xxxxxxxxxxx>
Date: Wed, 22 Mar 2000 17:02:47 -0600 (CST)
Reply-to: discussion@xxxxxxxxx

On Wed, 22 Mar 2000, Tom Hull wrote:

> The traditional Linux ps command used the BSD options, which are completely
> different from the SVR4 ps option. Someone came up with the idea of writing
> one program to support both option sets, where the SVR4 options switches
> are preceded by - while the BSD options don't start with -. The SVR4 ps -e
> lists _every_ process, which is not what ps e does; the corresponding BSD
> switch is: ps x

'ps e' and 'ps -e' produce the same output on my Debian 2.0 box... except
that any use of a - also gets...
   warning: `-' deprecated; use `ps e', not `ps -e'

Of course, I don't care for the idea that the dash on the flag is
deprecated... Unix commands should always use dashes to indicate flags.  

In this version of ps, the 'x' flag shows processes not attached to a tty,
not all processes.  'a' shows all processes.  'e' shows the environment
after the command line (which means it was pointless in my example, but I
didn't actually look at the ps output).  

Like I said, nobody agrees on exactly how ps should work.

> But that's the same as using ==. You could beat the optional [] with:

As far as I can tell, == is a numeric compare... I can't get it to match
anything that isn't a number.  
> The awk == operator (and other operators) does numeric comparisons if the
> operands look like numbers; otherwise it does a string compare. E.g.:

Your script wouldn't produce any output for me, but I've figured out that
it was a combination of things that caused it to fail... looking at the
wrong field and calling ps with the wrong option (it wouldn't match init
because it wasn't looking at all 

I then tried some tests by dropping the PROG thing and adding the text
directly... but it didn't match because I didn't put quotes around it. 

Of course, a problem with using == is that you have to either trim path
names off or know whether the program you're looking for was called with a
full path name or contains any other weirdness (like -bash, etc.)  If the
name is unique enough, regex match is easier... if it's a common pattern,
you have to jump through hoops to get exactly what you want. 

>   $ echo "1 1ax" | awk '{ print $1 == $2 }'
>   0
>   $ echo "1 1.0" | awk '{ print $1 == $2 }'
>   1

Sure... 1 may not be numerically equal to 1ax.  It's going to produce
those results whether it can compare strings or not if it interprets any
variable containing alpha characters as zero.  To prove your point, you
have to make == match a string, not show that a string doesn't match a
number.  (Though you don't have to prove your point, since I've seen
where I was doing it wrong.)

Carl D Cravens (raven@xxxxxxxxxxx)
Dogs crawl under fences, Software crawls under Windows.

-- This is the discussion@xxxxxxxxx list.  To unsubscribe,

[Prev in Thread] Current Thread [Next in Thread]