Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Grep has been acting strangely on one of my systems (Ubuntu Desktop - all my other systems are Ubuntu Server), and I can't figure out why. I created a control file named text that contains the following text:

grep
test!!

the following commands work on all of my systems except the problem child:

$ grep grep *
text:grep
$ grep 'test!!' *
text:test!!

On my problem child grep simply hangs. I have compared .bashrc, .bash_aliases, and even /etc/bash_completion, but I can't find the problem. Any ideas what could be causing the problem?

share|improve this question
1  
Does it work if you pass in the path name of the control file rather than * ? –  SiegeX Feb 8 '11 at 4:30
3  
It might also help if you could post the output of an strace. strace grep grep * –  Patrick Feb 8 '11 at 4:35
    
Did you try grepping after copying the test file from one of the machine where you did not have this problem? By the way how was the file created? maybe it may have something to do with utf ?!? –  yasouser Feb 8 '11 at 5:25
    
what does "type grep" say? –  chris Feb 8 '11 at 8:52
    
SiegeX: It does work, and it also works if I use 'tex*' –  JohnB Feb 8 '11 at 18:04
show 1 more comment

2 Answers

up vote 6 down vote accepted

On the problem machine, in the directory you grep 'something' * are there any special files like sockets, named pipes (fifos), etc. there ?

At least in the case of a named pipe, grep won't get an EOF from the named pipe until something actually writes an EOF to the named pipe.

share|improve this answer
    
Thanks for your input - if Patrick doesn't post an answer, you'll get the credit. –  JohnB Feb 8 '11 at 18:18
    
How would you do a grep -r and exclude named pipes? I've run into this problem too where grep hangs when it gets to a named pipe... –  Tyler Rick Mar 12 '12 at 18:51
    
I figured it out: Use 'grep --devices=skip -r ...' –  Tyler Rick Mar 12 '12 at 18:55
add comment

If it hangs, it sounds to me like it is looking for input from stdin.

You can prove that by typing Control-D (once only) - it will return to the shell.

If this is correct then * does not find any files.

share|improve this answer
    
<Ctrl>-D does not do anything - I need to use <Ctrl>-C to kill grep. I agree though - it sounds like it is looking for input from stdin. –  JohnB Feb 8 '11 at 17:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.