Linux shell:cat << EOF

1 purpose

Read a block of text from standard input (stdin), stop reading at "EOF", and output the text to standard output (stdout).

2 Grammar

cat << EOF
文本信息
EOF

Key syntax instructions:

  • << : Here Document format syntax start identifier in Linux;
  • EOF : An identifier that identifies the beginning and end of text information, which can be any custom character, such as begin, data, etc.
  • Text message : what the user (you) wants to display on the terminal.

3 Difference between '<< EOF' and '<<- EOF'

If the redirection operator is <<-, then all leading tab characters are stripped from input lines and the line containing delimiter.  

The Chinese meaning is that if the redirection operator is <<-, then the leading tab (tab) in each line of text information and the end identifier (such as EOF above) is ignored .

#!/bin/sh

#line 1、2、3,EOF,data 1、2、3 前面为 tab,不是空格。
cat <<- EOF
        line 1
        line 2
        line 3
        EOF

cat << DATA
        data 1
        data 2
        data 3
DATA

Results of the:

picture

You see,   the output using '<<-' ignores the tabs in front of each line .

4. Extend

What should I do if I want to input multiple lines of text into a file from the terminal?

cat > file << EOF
information 1
information 1
information 1
...
EOF

Guess you like

Origin blog.csdn.net/ygq13572549874/article/details/131819790