Here Document code block there is a special use, and he uses the redirection IO recorded in the form of text or some temporary interaction commands, and these text or commands are sequentially transmitted to a program or a command, as his runtime standard input.
Here document syntax is
void@void-ThinkPad-E450:~/linuxShellArg$ command << delimiter > document > docuemnt > document > delimiter
<< bash as the operator inputs an instruction, the latter is an identifier of the start and end delimiter identifier, the output will always bash> prompt, the user waits for input data, up to the second user input until the delimiter identifier he indicates that the input end. Delimiter between two data will be used as a standard command command input.
Delimiter identifier may be any string, but only a word delimiter, intervening spaces or Tab.
Here document often used to help function o Shell scripts, for example, the android build / envsetup.sh
function hmm() { cat <<EOF Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment: - lunch: lunch <product_name>-<build_variant> - tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5] [eng|userdebug|user] - croot: Changes directory to the top of the tree. - m: Makes from the top of the tree. - mm: Builds all of the modules in the current directory, but not their dependencies. - mmm: Builds all of the modules in the supplied directories, but not their dependencies. - mma: Builds all of the modules in the current directory, and their dependencies. - mmma: Builds all of the modules in the supplied directories, and their dependencies. - cgrep: Greps on all local C/C++ files. - jgrep: Greps on all local Java files. - resgrep: Greps on all local res/*.xml files. - godir: Go to the directory containing a file. Look at the source to view more functions. The complete list is: EOF T=$(gettop) local A A="" for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do A="$A $i" done echo $A }
In the HMM function () is shown here document some help information, here document where the output to the screen by the cat command, and uses the delimiter identifier EOF.