分界符 EOF 不能使用反引号,反斜杠转义的技巧
在分界符EOF前添加反斜杠\,或者用单引号、双引号括起来:
mysql -h 172.16.20.20 -u root -p'abcdefg5'<<"EOF"
DROP DATABASE `prod-erp`;
CREATE DATABASE `prod-erp` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
use `prod-erp`;
source test-erp.sql;
EOF
---------------------------------------------------------------------------------------------------------------------
cat >> a.sh << \EOF
echo `hostname`
echo $HOME
EOF
cat >> a.sh << "EOF"
echo `hostname`
echo $HOME
EOF
cat >> a.sh << 'EOF'
echo `hostname`
echo $HOME
EOF