Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

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
asdf
fdsa

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
asdffdsa

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

share|improve this answer

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.