shell中 EOF

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hongrisl/article/details/88724196

EOF 

 Shell中通常将EOF与 << 结合使用,表示后续的输入作为子命令或子Shell的输入,直到遇到EOF为止,再返回到主调Shell。
 可以把EOF替换成其他东西,意思是把内容当作标准输入传给程序。

 回顾一下< <的用法。当shell看到< <的时候,它就会知道下一个词是一个分界符。在该分界符以后的内容都被当作输入,直到shell又看到该分界符(位于单独的一行)。这个分界符可以是你所定义的任何字符串。

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

[root@sys ~]#

把内容追加到/root/testeof.txt 直到遇到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 '[email protected]_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
 

猜你喜欢

转载自blog.csdn.net/hongrisl/article/details/88724196
EOF
今日推荐