Linux Shell Learning notes 7--here Document__linux

Source: Internet
Author: User
Tags comments


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 ignoredAdding ' 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!





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.