Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

After search it seems the ascii of EOF is -1,but how can I echo it out?

My purpose of doing this is to test whether it behaves the same as pressing ctrl-d if I just echo out EOF.

share|improve this question

closed as off-topic by kasperd, Andrew Schulman, Jenny D, Cristian Ciupitu, gtirloni Oct 1 at 15:33

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must be relevant to professional system administration. Server Fault is dedicated to professional system and network administrators. End user and enthusiast questions are off-topic (contact your system administrator or hire a professional to help you out). Please see the Help Center for more information." – kasperd, Andrew Schulman, Jenny D, Cristian Ciupitu, gtirloni
If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

up vote 4 down vote accepted

There is no way to echo out an EOF. An EOF can only be generated either by reaching the end of a file or by invoking the keypress bound to the eof terminal setting (CtrlD by default) when the file being read is bound to the terminal.

share|improve this answer
    
isn't EOF defined as -1 in stdio.h? why can't echo it out if we know its ascii value? –  locale Jun 8 '11 at 9:13
    
So what. An int with the value of -1 (or 4294967295 if we consider the unsigned version) can't possibly be a character anyway since characters can only have a value from 0 to 255 inclusive. –  Ignacio Vazquez-Abrams Jun 8 '11 at 9:15
    
how do you know it's an int in the first place? –  locale Jun 8 '11 at 9:18
3  
Because I do things like look at the fgetc(3) man page. –  Ignacio Vazquez-Abrams Jun 8 '11 at 9:20

In bash you could write exec 1>&- in order to close the file descriptor known as stdout.

As Ignacio already said, EOF is not a character, so the question how to "echo EOF" doesn't make any sense in the first place. You can echo characters (bytes) or you can close a file descriptor, but you can never echo an EOF.

share|improve this answer

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