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.

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?

share|improve this question
    
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

2 Answers 2

up vote 11 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
share|improve this answer
5  
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
4  
@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

In your first example, you need an echo:

user$ echo "blue" | md5
share|improve this answer
    
it's useless. Idea was, all input is pressed by keyboard. Problem was how to mark stream end. –  Znik Feb 25 at 9:47

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.