Link to home
Start Free TrialLog in
Avatar of bganoush
bganoush

asked on

Position of option changes the behavior in grep...


grep is weird!

no wait... it's unix, it's supposed to be weird!!!

Anyway, I was just wondering if any other Unixes have the same behavior as this...  (I'm using AIX.)

When I type:
   grep -l "pattern" *

I get the output:
    fileone.ext
    filetwo.ext
    filethree.ext

but when I type:
   grep "pattern" -l *

I get the output:
    fileone.ext: this line contains the word pattern.
    filetwo.ext: this line does not contain the word pattern.... DOH!
    filethree.ext: will this line cause someone to launch a patternity suit?

The man entry for grep only says that the first case should happen.

-- Bubba
Avatar of chris_calabrese
chris_calabrese

The options always come first on the Unix command line.

'grep -l pattern *' means to look for 'pattern' in all files in the current directory with the -l option set

'grep pattern -l *' means to look for 'patten' in a file called '-l' plus in all files in the current directory, with no options set
... and BTW, everything else is weird, UNIX is normal <LOL>
>> The options always come first on the Unix command line.

need not be always true

you can have

cp -i  file1 file2  
or
cp file1 file2 -i

both of which will do the same thing ,

but yes in the case of grep you are right ...

>> The options always come first on the Unix command line.
i.g. not true

to be more precisious on grep:
 standard (AT&T) grep requires options before pattern, while Gnu's grep does not
AIX (and most other proprietary Unix) use standard grep by default
Avatar of bganoush

ASKER


That's weird... (or normal whatever the case may be...)

If AIX uses "standard" grep, then why did I get the second output???  I don't have a file called "-l"...

>> UNIX is normal

Oh cool.. then I'm normal too!!!  yippeee!  anyone see my socks?

-- Bubba
sometimes AIX seems to be wired and Unix is standard (as my socks are;-)

Some people wear socks of different colors or socks that are just weird...

But in my case, I sometimes lose count after about 9 or 11... and then I run out of places to hang them...

I also think AIX is wired.. and weird...

-- Bubba
ASKER CERTIFIED SOLUTION
Avatar of gheist
gheist
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial








                                                                 that's weird







gheist, could give a :-( or :-)
i.g. I prefer standards, but POSIX is one of those which gots outdated by reality (like Gnu)
We could argue what''s the better one, but Gnu is there and works, stupid simple, just works ;-.)