shell里使用EOF时报错

#!/bin/bash
for i in S45202.*
do
gnuplot << EOF
set term postscript eps enhanced color
set output "$i.eps"
set title "Spectrum"
set xlabel "Wavelength [{/Symbol l}]"
set xtics 5 set ylabel "Intension"
set ytics 500
set grid
set nokey
plot "$i" using 1:2 with lines
EOF
done

tmp.sh:行21: 警告:立即文档在第 12 行被文件结束符分隔 (需要 `EOF ')

tmp.sh:行22: 语法错误: 未预期的文件结尾

竟然没找出错误来,自己写了一个没有错,纳闷中

#!/bin/bash 

if [ ! -f /usr/test/auto.cfg ];then

touch /usr/test/auto.cfg
fi
cat >/usr/test/auto.cfg <<'HERE'
{
BU_code=Z000232
ETHER=enp6s0
DB_IP=192.168.118.188
DB_pwd=34Trx7P6bQCjbKkFWO5eQqMxQ1a0LVB8
DBServer_port=22
}
HERE

'HERE'加引号的会把里面的变量原本的输入到auto.cfg里,不加引号则会把变量的值输入到auto.cfg.

比如

#!/bin/bash 

BU_code=Z000232
ETHER=enp6s0
DB_IP=192.168.118.188
DB_pwd=34Trx7P6bQCjbKkFWO5eQqMxQ1a0LVB8
DBServer_port=22

if [ ! -f /usr/test/auto.cfg ];then

touch /usr/test/auto.cfg
fi
cat >/usr/test/auto.cfg <<'HERE'
{
BU_code=$BU_code
ETHER=$ETHER
DB_IP=$DB_IP
DB_pwd=$DB_pwd
DBServer_port=$DBServer_port
}
HERE

 cat /usr/test/auto.cfg

BU_code=$BU_code
ETHER=$ETHER
DB_IP=$DB_IP
DB_pwd=$DB_pwd
DBServer_port=$DBServer_port

不加引号时

cat /usr/test/auto.cfg

BU_code=Z000232
ETHER=enp6s0
DB_IP=192.168.118.188
DB_pwd=34Trx7P6bQCjbKkFWO5eQqMxQ1a0LVB8
DBServer_port=22

 

转载于:https://www.cnblogs.com/aliuwoai/p/10346274.html

你可能感兴趣的:(shell里使用EOF时报错)