Site Tools


eof

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

eof [February 18, 2026 at 01:32] – created yanevskiveof [May 14, 2026 at 11:38] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +# 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 <stdio.h>
 +#include <ctype.h>
 +
 +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