Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I press Ctrl+D to end standard input, but it only works if I'm on a fresh line. And that requires me to push Enter first, which puts an unwanted new line character in there. Is there any way around that?

share|improve this question
This is in bash? Running a script or a program (in C, C++)? – Huckle Apr 3 '12 at 17:32
@Huckle: Any program that reads from standard input. – Benjamin Lindley Apr 3 '12 at 19:17
up vote 2 down vote accepted

Ctrl-D does not works only on a fresh line as you says. Take rev for example, which reverses each input line.

Normally, you press Enter after input, and it reverse that line:

$ rev

But if you do not want to append a newline to your input, just press Ctrl-D twice after you input asdf, it is also reversed, but in the same line:

$ rev

Also, different programs handles this differently, for example bc does not behave like above.

share|improve this answer

Your Answer


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.