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?

  • 2
    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. May 12 '10 at 8:28

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
  • 7
    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. May 12 '10 at 7:57
  • On WSL using openssl md5 I have to press Ctrl-D 3 times. By 2030 we should have to press it 4 times at this rate.
    – Robert
    Feb 18 at 18:23

In your first example, you need an echo:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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