Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've copied a large e-mail (raw text) from one web terminal. I can paste that into the terminal, but I want to feed it to sa-learn. I was thinking one thing I could do here is use heredoc's. This syntax appears to work.

$ echo <<EOF | sa-learn --spam
<paste email>

However, it doesn't seem to work...

$ echo <<EOF > foo

$ cat foo

How does a heredoc work in bash?

share|improve this question
Interestingly enough cat > foo <<EOF would work, and sa-learn --spam <<EOF... what does the syntax that I've given do though, and why does it fail silently. – Evan Carroll Feb 29 '12 at 20:54
up vote 3 down vote accepted

echo prints its arguments and ignores stdin. <<EOF ... EOF (a here document / heredoc) writes to stdin. As you noticed, cat reads from stdin (and writes it out), so it does read the heredoc. As sa-learn reads from stdin, it also reads the heredoc.

share|improve this answer
That makes sense.. <<EOF ... EOF is putting the input in STDIN not a file ... wonder why I why was thinking it was dropping it @ARGS.... – Evan Carroll Feb 29 '12 at 21:18

For anyone reading this question who happens to use Mac OS X, look at pbpaste(1). It takes whatever's on your clipboard (NeXTStep used to call this the pasteboard, and the Cocoa APIs still do, hence the "pb") and outputs it to stdout. So on a Mac you could do this with:

pbpaste | sa-learn --spam

Note also the related pbcopy(1).

share|improve this answer

I wonder if Ctrl+X, Ctrl+E would help here.

It allows you to quickly open an editor to write a long command. There also seem to be alternatives.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .