4

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?

2
  • This is in bash? Running a script or a program (in C, C++)?
    – Huckle
    Apr 3, 2012 at 17:32
  • @Huckle: Any program that reads from standard input. Apr 3, 2012 at 19:17

1 Answer 1

7

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

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

$ rev
asdf
fdsa

If you do not want to append a newline to your input, just press Ctrl-D twice after you input asdf, it will be reversed in the same line:

$ rev
asdffdsa

Different programs handle this differently; for example bc does not behave like above.

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.