-2

Learning command line as basis for further web development learning. Using a Mac whenever I try to use GREP or CAT, Terminal hangs up. Once I enter the process it displays in the top border, but nothing happens. What am I doing wrong?

1 Answers1

1

If you just type

$ cat

at the command line, the shell will wait for further input, because you haven't given it any input to work on.

cat will take its input and send it to wherever you're sending its output. By default, this is to stdout: the terminal. So you can start with something like this:

/Users/jpk/:510 $ cat 
dog boy van
dog boy van
foo bar baz
foo bar baz
^D
/Users/jpk/:511 $ 

When I type cat and hit return, the shell waits until some input comes in, and then it redirects that to the output. This goes on until I send an end-of-file signal (^D)

I'm not sure what you're seeing for grep - when I just type a bare grep and hit enter, I get usage notes:

/Users/jpk/:512 $ grep
usage: grep [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
    [-e pattern] [-f file] [--binary-files=value] [--color=when]
    [--context[=num]] [--directories=action] [--label] [--line-buffered]
    [--null] [pattern] [file ...]

/Users/jpk/:513 $ 
Jon Kiparsky
  • 7,499
  • 2
  • 23
  • 38
  • That's not quite correct. `grep` by itself is certainly a complete command. The reason the shell waits is because if a filename is not given, input is expected to come from STDIN. – Jordan Running Dec 03 '14 at 23:09
  • That's correct - I was actually editing that just now. :) Thanks for the correction. – Jon Kiparsky Dec 03 '14 at 23:11