Indicating end of Standard Input

12

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?

waiwai933

Posted 2010-05-12T04:31:42.247

Reputation: 2 293

2Your 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 – 2010-05-12T08:28:53.293

Answers

16

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

bryan

Posted 2010-05-12T04:31:42.247

Reputation: 7 848

6This 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 – 2010-05-12T05:29:10.237

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 – 2010-05-12T07:57:50.083

0

In your first example, you need an echo:

user$ echo "blue" | md5

Paused until further notice.

Posted 2010-05-12T04:31:42.247

Reputation: 86 075

it's useless. Idea was, all input is pressed by keyboard. Problem was how to mark stream end. – Znik – 2014-02-25T09:47:21.227