Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

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

3 Answers 3

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.