En el script de shell cat << eof, aparece la salida de error

En el script de shell cat << eof, hay una salida de error


Primero, veamos la salida normal;

// 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
*******************

No hay ningún problema con el uso normal;

Cuando usamos la tecla Tab al escribir un script;

// 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

Hay un código de error;

En este momento, solo necesitamos agregar-after <<
para resolver este problema;

// An highlighted block
cat test.sh
#!/bin/bash
	cat <<-eof
	*******************
	test eof
	*******************
	eof
// An highlighted block
[root@haha ~]# sh test.sh
*******************
test eof
*******************

Supongo que te gusta

Origin blog.csdn.net/weixin_52441468/article/details/112208735
Recomendado
Clasificación