1、使用\消除文件中元字符的含义
cat > .profile << EOF
echo "Hello World"
echo "Current Date and Time:"\`date\`
EOF
如果不用\消除`的含义,shell会在运行该脚本时执行date命令,并将当前时间写入文件,.profile文件中的内容是
echo "Hello World"
echo "Current Date and Time:"2021年 11月 10日 星期三 16:46:22 CST
2、在分界符EOF前添加反斜杠\,或者用单引号、双引号括起来
cat > .profile << \EOF
echo "Hello World"
echo "Current Date and Time:"`date`
EOF
cat > .profile << 'EOF'
echo "Hello World"
echo "Current Date and Time:"`date`
EOF
cat > .profile << "EOF"
echo "Hello World"
echo "Current Date and Time:"`date`
EOF
当用脚本向文件中写入多行命令时,使用这种方法更加方便