How does one indicate that one has finished entering test in stdin?

For example, let's say that I wish to encrypt 'blue' using MD5 (I know MD5 is unsecure, but just for this example). I tried

user$ blue | md5

which I was led to understand is how one pipes input to stdin, but it doesn't work right.

But if I just enter

user$ md5

I can enter the word 'blue'. But how do I indicate to md5 that I'm finished entering text?

link|improve this question

60% accept rate
Your first attempt probably did not work correctly because you were trying to execute blue as a command instead of echoing it. Try echo blue | md5 instead. – Trey Hunner May 12 '10 at 8:28
feedback

2 Answers

up vote 6 down vote accepted

are you talking about getting an md5sum for a piece of text?

if so run the md5sum command

type your text, when finished move to a new line by pressing return

press CTRL-D to end your input.

 user$ md5sum
 blue
 CTRL-D
link|improve this answer
2  
This is the right answer. Ctrl-D is the canonical way to terminate keyboard stdin in any shell command. But strangely, I have an /sbin/md5 -- of indeterminate origin, but probably from OpenSSL -- on my system (Mac OS X v10.6.3) that doesn't terminate on the first Ctrl-D. It takes a second Ctrl-D to terminate it. Same with openssl md5. – Spiff May 12 '10 at 5:29
2  
@Spiff: You should only need two ^D if you want to omit the final newline. If you can accept (or need) the final newline, then a single ^D on a fresh line should suffice. The EOF character (^D) flushes buffered input. If there is no buffered input, the process reading from the tty gets a zero length read (i.e. EOF). See (e.g.) POSIX XRAT 11.1.9, EOF; VEOF in Linux termios; or EOF in FreeBSD termios. – Chris Johnsen May 12 '10 at 7:57
feedback

In your first example, you need an echo:

user$ echo "blue" | md5
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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