grep is always recursive

Hal Burgiss hal at burgiss.net
Sat Jan 24 17:23:24 UTC 2009


On Sat, Jan 24, 2009 at 05:29:22PM +0100, Loïc Grenié wrote:
>     You can try to use strace to see what happens. Something
>   like:
> 
> strace -o /tmp/trace bash
> grep something *
> <Ctrl-C> after some time
> exit
> 
>    Try whether sh -c 'grep something *' has the same behaviour.
>   In that case strace -o /tmp/trace sh -c 'grep something *'
>   will be the same (but easier)
> 
>     Then grep execve /tmp/trace to see whether grep is called
>   as grep -r or not and to check which grep is executed.

halb at honey:~$ grep execve /tmp/trace 
execve("/bin/grep", ["grep", "a", "2007-11-11--21.51.35",
"2007-11-12--21.50.37", "2007-11-25--11.50.58", "ascii.art", "attic",
"bin", "blogs", "blogs~", "cd_addressbook2.csv",
"cd_addressbook3.csv", "cd_addressbook.csv", "cd-montly.txt",
"checkdbs.sh", "clients", ...], [/* 36 vars */]) = 0

The actual command was 'grep a *'.

Some of the listings there are directories. But I don't see any reason
for grep itself to act recursively. Interestingly, I find this only
happens in $HOME. If I cd to somewhere else, grep acts as expected.
Very strange. 

I am wondering now if bash has expanded '*' to include directories.
But if so, why only in $HOME? And why only on this system?

Thanks.

-- 
Hal





More information about the ubuntu-users mailing list