Monday, November 28, 2005

Redirecting Standard Input

Start like this:

  1. cat
    hello, world
    hello, world
    ^D

  2. cat copies the input that you type -- standard input, or stdin -- to the screen.
    Next, redirect output to a file.
  3. cat
    cat > FOO
    hello, world
    ^D

  4. This puts the string "hello, world" into the file, FOO.
    You can check it by looking at the contents of FOO.
  5. cat FOO
    hello, world

  6. Finally, use the command history and editing keys to recall command [2], change
    the '>' to a '<', and to press a carriage return.
  7. cat < FOO

  8. With '<' the arrowhead points from the file toward the command,
    redirecting the contents of the file FOO into the command cat.

Part of learning the shell is losing your fear of making mistakes. The sooner you make your first 5000 mistakes, the better. What do these do?
cat < FOO > BAR
< FOO > BAR cat
< cat > BAR
BAR < > cat

0 Comments:

Post a Comment

<< Home