eof
Differences
This shows you the differences between two versions of the page.
| eof [February 18, 2026 at 01:32] – created yanevskiv | eof [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:// | ||
| + | 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: | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | int ch; | ||
| + | while ((ch = fgetc(stdin)) != EOF) { | ||
| + | putchar(toupper(ch)); | ||
| + | } | ||
| + | return 0; | ||
| + | } | ||
| + | ``` | ||
| + | |||
| + | ## Links | ||
| + | |||
| + | - https:// | ||
| + | - https:// | ||
