3

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>
EOF

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

$ echo <<EOF > foo
AOSJFDOASDFJKOK
EOF

$ cat foo
(nothing)

How does a heredoc work in bash?

1
  • 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. Feb 29, 2012 at 20:54

3 Answers 3

4

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.

1
  • 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.... Feb 29, 2012 at 21:18
4

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).

1

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.

You must log in to answer this question.

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