Please add CODE tags (as required by forum rules) to your post. Without them we can't tell where your script ends, we can't tell if spacing at the start of various lines in your script is a problem, and we can't tell what is intended to be output produced by your script.
Here Documents
This type of redirection instructs the shell to read input from the
current source until a line containing only word (with no trailing
blanks) is seen. All of the lines read up to that point are then used
as the standard input for a command...