What does eof in linux mean?

藏色散人
Release: 2023-04-13 10:53:52
Original
3984 people have browsed it

Linux's eof is a custom terminator, its full name is "END Of File"; eof is not fixed, you can set an alias at will, press "ctrl-d" in Linux to represent eof; eof generally With cat, multiple lines of text can be output.

What does eof in linux mean?

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

What does eof in Linux mean?

How to use EOF in shell basics

1. How to use EOF

EOF is the abbreviation of (END Of File), which represents a custom terminator. Since it is customized, EOF is not fixed. You can set the alias at will. Press ctrl-d in linux to represent EOF.

EOF usually works with cat to output multi-line text.

## Its usage is as follows:

##<#Start

##....

#End You can also customize, for example:

<# Start

....

ABC            

#End

Using cat with redirection, you can generate files and append operations. Before doing it, be familiar with a few special symbols

##< : Input redirection

>: Output redirection

##>>

: Output redirection, will be appended, will not overwrite the previous content

##< ;<

: Standard input comes from the middle of a pair of delimiters on the command line## Example

1

##[root@ren5 ~]# cat <> ; hello

> EOFhello

We know that the operation object of cat is a file, but in example 1, the operation object of cat is not a file, but a user Input; then we can understand example 1 like this: first enter "Hello" in the file file, and then use cat file to output it Content.

That is to say, we can use a file to replace "<< EOF EOF".

On the other hand, if the file in the operation command is the input object, you can also use "<< EOF EOF" Replacement.

Example2

[root@ren5 ~]# cat 1.txt

abc

[root@ren5 ~]# cat < 1.txt                                 Enter the overlay content into file 1.txt (you can also: cat > 1.txt <)

# #> 123

> 456

> 678

##> LOL

> EOF

[root@ren5 ~]# cat 1.txt

123

456

678

LOL

"

<< EOF EOF" is used for user-defined input during command execution. It is similar to the role of a temporary file, but is smaller than Using files is more convenient and flexible. 2. The difference between cat <

Both are obtained

stdin, and ends stdin at EOF, and outputs stdout. ##When we use

cat <, after we complete the input, we need to enter on a new line EOF ends the input of stdin. EOF must be written on the top line, and cannot be preceded by tabs or spaces. If the redirection operator is

<<-, then the delimiter ( EOF) Tab characters (Tab) at the beginning of the line will be removed. This resolves tabs caused by natural indentation in scripts.

Example

1[root@ren5 ~]# cat 2.sh

#!/bin/bash

##cat <

##Hello, EOF! ##EOF

[root@ren5 ~]# sh 2.sh

Hello,

EOF! [root@ren5 ~]# sh 2.sh

##2.sh:line

4 :

Warning:Immediate document at line 2 is delimited by end-of-file (requires `EOF') Hello,

EOF

! ## EOF

If there is a tab or space before the end decomposition character EOF

, Then

EOF will not be regarded as the end delimiter, and will only continue to be entered as stdin. Example

2

: [root@ren5 ~]# cat 2.sh

#!/bin/bash

cat << -EOF

Hello, EOF

!

## EOF

[root@ren5 ~]# sh 2.sh

##Hello,

EOF!

Although the final EOF is preceded by multiple tabs and spaces, it will still be regarded as the end delimiter, indicating ## The end of #stdin.

Recommended study: "linux video tutorial"

The above is the detailed content of What does eof in linux mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template