The role of eof in shell scripts

What is the use of the EOF command inside the linux shell




EOF can be replaced with something else

Meaning that the content is passed as standard input to the program

What does eof mean?

In C, or more precisely in the C Standard Function Library, it means end-of-file (endoffile). EOF is used as the end-of-file flag in while loop, such a file with EOF as the end-of-file flag must be a text file.

In a text file, data is stored as ASCII code values of characters. We know that the range of ASCII code values is 0~127 and -1 is not possible, so EOF can be used as the end-of-file flag.

How it works:

Input from a terminal never really “ends” (unless the device is disconnected), but it is useful to partition the input from a terminal into multiple “files”, so a key sequence is preserved to indicate the end of the file. key sequence is preserved to indicate the end of the input.

In UNIX and AmigaDOS, the translation of keystrokes into EOFs was done by the terminal driver, so applications did not need to distinguish the terminal from other input files. drivers on Unix platforms transmitted an end-of-transmission character (Control-D, encoded as 04 in ASCII) at the beginning of the line to indicate the end of the file.

In AmigaDOS, the driver transmits an end-of-transmission character (Control-D, ASCII code 04) at the beginning of the line to indicate the end of the file (Control-D is used as the break character). To insert a real Control-D character into the input stream, the user needs to put a “quoted” command character in front of it (usually Control-V, which means that the next character is not used as a control character, but is used literally).

The meaning of <<EOF

su: switch user

-:use orcale’s environment settings

-c: execute the command that follows

<<EOF: because sqlplus wants to enter the username and the password so the two lines that follow are entered separately.

When EOF occurs on the third line, the shell considers the input to be complete; it passes the input to the sqlplus command

<<eof can be any string, such as “<<laldf”, so when you enter the single line laldf, the shell considers the input to be complete;

EOF usage in yum source shell script automated install






The meaning of this paragraph is:

Writing what is between the two EOFs to /etc/yum.repos.d/abc.repo will overwrite the original.

The one below is appending the content without overwriting the original




< p>gpgcheck=0


This piece of code uses HereDocument from shell, you can baidu some information to see.