shell脚本中cat << eof ,出现错误输出
首先,我们先看下正常的输出;
// An highlighted block
[root@haha ~]# cat test.sh
#!/bin/bash
cat << eof
*******************
test eof
*******************
eof
// An highlighted block
[root@haha ~]# sh test.sh
*******************
test eof
*******************
正常的使用是没有没问题的;
当我们写脚本时使用Tab键后;
// An highlighted block
[root@haha ~]# cat test.sh
#!/bin/bash
cat << eof
*******************
test eof
*******************
eof
// An highlighted block
[root@haha ~]# sh test.sh
test.sh: line 6: warning: here-document at line 2 delimited by en
d-of-file (wanted `eof') *******************
test eof
*******************
eof
就出现了错误代码;
这时候,我们只需要在<<后加上-
就可以解决这个问题;
// An highlighted block
cat test.sh
#!/bin/bash
cat <<-eof
*******************
test eof
*******************
eof
// An highlighted block
[root@haha ~]# sh test.sh
*******************
test eof
*******************