Here document is one of the ways in which you define block variables in bash.
The form of the definition is:
Command <
...
...
...
Here
Its role can be used to define a variable, the command and the content between here using the way to input to the command to deal with. where here is the equivalent of a tag, can be any string .
Use here document for variable setting:
[Root@localhost ~]# wow= ' wow,great! '
[Root@localhost ~]# m1=$ (cat <
echo $m 1 line
1 is good. They are Jack,marry and John. wow,great!
As the above example is written
(Cat << "Here") means that this here document has the same characteristics as double quotes, that is, the ability to support variable substitution .
can also be used to define a comment,
use here document to do multiple comments, the method is:
: <Here
: Stands for doing nothing
Originally bash only supports single-line annotations (with #) and is now available for multiline annotations.
Note here also has a special usage:
is in front of here.
on--or to add ",
Plus-Indicates that all tab keys in the following text segment will be ignored,
Adding ' indicates that the following general variable definition is used ' will cause the variable to render the WYSIWYG form, or to turn off the variable substitution, or to replace it with a "double quote ".。
[Root@localhost ~]# cat<<-' here '
> 1 is good.
> They are Jack,marry and John.
> $WOW
> here
good the 1 is.
They are Jack,marry and John.
$WOW
Use here Document
, package The original code for the C (or other program language). This is the cracker spread the vulnerability program, the favorite method。
1 #!/bin/bash
2 # Filename:create_prg.sh
3 echo "Creating hello.c ..."
4 echo
5 cat << ' EOF ' > hello.c
6 #include <stdio.h>
7
8 int main ()
9 { printf ("Hello world!\n");
return 0;
compiling hello.c
echo
#compile hello.c,create The excutable F of the "EOF" Ile
gcc-o Hello hello.c
#if compile successfully,then excute it
if [$-eq 0];then
22 echo "Excute hello ..." echo chmod u+x Hello /hello Echo ' Compile error:hello.c '
fi
Lines 5 through 13 use here document to smuggle a hello.c program's source code, execute the script will produce hello.c, then call GCC compile hello.c, if compile correctly, "execute" (Start attack) program file hello.
This is the prototype of the shell script that carries the attack.。 Execution results:
[Root@localhost sh]#./create_prg.sh
creating hello.c
... Compiling hello.c
... Excute Hello ...
Hello world!