Tuesday, November 29, 2005

Here Documents

Ouput has '>' and '>>'. Now that you've seen '<', what about '<<'?
cat <<FOO
hello world
FOO
This is a here document, which says "Take input from from 'here to FOO'"

Actually, FOO can be a little visually confusing, because I often use FOO and foo for variable or file names, so I usually use a marker for "End of Input" or "End of File" instead, like __EOF__ or __EOI__. These stand out and I don't use them for other things.

If you want to imbed the contents of a file into a script, a here document is a good way to do it.

As usual, you should try out moving around the redirects, and use command history to do it.

There's even a '<<<'
H='hello, world'
cat <<< $H
It's sort of a "right here" document, which provides input from the current line.

0 Comments:

Post a Comment

<< Home