# EOF **EOF** is an acronym that stands for "End of file" ## Shell In shell, EOF is commonly used as a terminator in what is called a [heredoc](https://en.wikipedia.org/wiki/Here_document) ("here document"). It's when you want to supply a multiline text to a command to its standard output, using `<<`. ``` $ cat > hello.txt << EOF Here, you can write anything you like. It's not over until you actually type E-O-F. You can cancel with Ctrl + C. EOF ``` But this is just a convention. You can use any string you like in heredocs. ``` $ cat > hello.txt << whatever Now you can type EOF EOF EOF as much as you want until you type it whatever ``` ## C In C programming language, EOF is a constant defined `-1` which indicates an end of file. ```c // Compile: gcc main.c -o program // Run: echo 'Hello world' | ./program // Output: HELLO WORLD #include #include int main() { int ch; while ((ch = fgetc(stdin)) != EOF) { putchar(toupper(ch)); } return 0; } ``` ## Links - https://en.wikipedia.org/wiki/End-of-file - https://stackoverflow.com/questions/1782080/what-is-eof-in-the-c-programming-language