SUMMARY: KSH behavior (* -vs- no *)

From: E. Richard Glazier (erglazier@hotmail.com)
Date: Tue Nov 19 2002 - 12:45:15 EST


Thanks to everyone who responded, which was about 25 people! They all said
essentially the same thing. In summarary, the '*' is being interpreted by
the shell before it is passed to grep. The difference in my two machines
was where I was sitting in the directory structure. 'ps -ef | grep ora*'
returned results when I was sitting at / because of all the files and
directories that start 'ora' under /. Some suggested doing an echo ora and
an echo ora* from my directory location as a means of seeing how the ora*
would be interpreted.

I did a quick test on my own machine. From /etc I did an 'echo rc*'. It
returned rc.config and rc.config.common. I then did a 'set +x' and then
'grep rc*'. My statement was interpreted as 'grep rc.config
rc.config.common', and two lines were returned containing 'rc.config'. I
lastly did 'grep rc.config rc.config.common' and got the same output.

I selected one response that summarizes this, and represents most responses
I got.

On Mon, Nov 18, 2002 at 06:14:34PM +0000, E. Richard Glazier wrote:
>This is only just to satisfy my curiosity.
> > I have 2 GS80s running 5.1 PK5. They are exactly the same. When logged
>in as root on each machine (ksh is root's shell on each), I get different
>output from 'ps -ef | grep ora*' One machine returns about 30 processes
>that start 'ora' and the other machine returns nothing. It seems one
>machine returns anything that starts 'ora', and the other is looking
>specifically for a process 'ora*'. Using 'ps -ef | grep ora' will work on
>both machines. What's causing the difference in the metacharacter
>interpretation?

the ora* is interpreted by the shell, not grep, so the command that gets
run depends on what's in your current directory. For example, if you
have a file called oral_hygiene in the current directory, then running:

ps -ef | grep ora*

will actually run

ps -ef | grep oral_hygiene

which will of course return nothing (unless you do happen to have a
program running called oral_hygiene - stranger things have been known!)

It emphatically *won't* find your oracle processes.

The * is completely unnecessary for what you're trying to do; just leave
it out. It also looks like you're expecting the * to work as it does
for ls and so on. Grep can accept wildcards, but:

(a) You need to put them in quotes to stop the shell globbing expanding them

(b) They use regular expression rules, not file globbing rules.

So, as an example, suppose you wanted to look for processes like
orafoodb and orabard you would do something like this:

ps -ef | grep 'ora[a-z]*db'

Tim

--
Dr Tim Cutts
_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE* 
http://join.msn.com/?page=features/junkmail


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 10:49:00 EDT