< EOF in linux

Keywords: yum EPEL shell iptables

1,EOF 

In Shell, EOF is usually used in combination with < to indicate that the subsequent input is used as the input of subcommand or subshell, until EOF is encountered, and then returned to the calling Shell.
EOF can be replaced by something else, meaning that content is passed to the program as standard input.

Review the use of <. When the shell sees < < it knows that the next word is a delimiter. What follows the delimiter is treated as input until the shell sees the delimiter again (on a separate line). This delimiter can be anything you define character string.

[root@sys ~]# cat > /root/testeof.txt <<EOF
> HELLO
> WELCOME TO CHINA
> EOF
[root@sys ~]# cat testeof.txt
HELLO
WELCOME TO CHINA

[root@sys ~]#

Append content to / root/testeof.txt Until EOF

if [ -f /etc/redhat-release -a -n "`grep ' 7\.' /etc/redhat-release`" ];then
    #CentOS_REL=7
    if [ ! -e /etc/yum.repos.d/epel.repo ];then
        cat > /etc/yum.repos.d/epel.repo << EOF
[epel]
name=Extra Packages for Enterprise Linux 7 - \$basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/\$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=\$basearch
failovermethod=priority
enabled=1
gpgcheck=0
EOF
    fi
    for Package in wget make openssl gcc-c++ ppp pptpd iptables iptables-services 
    do
        yum -y install $Package
    done
    echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf
elif [ -f /etc/redhat-release -a -n "`grep ' 6\.' /etc/redhat-release`" ];then
    #CentOS_REL=6
    for Package in wget make openssl gcc-c++ iptables ppp 
    do
        yum -y install $Package
    done
    sed -i 's@net.ipv4.ip_forward.*@net.ipv4.ip_forward = 1@g' /etc/sysctl.conf
    rpm -Uvh http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm
    yum -y install pptpd
else
    echo -e "\033[31mDoes not support this OS, Please contact the author! \033[0m"
    exit 1
fi

Posted by brij_theinvader on Sun, 03 May 2020 04:57:15 -0700