Your here-document is behaving weirdly. You tried to maintain a … Preventing Weird Behavior in a Here-Document in bash