How can I have a newline in a string in sh?

If you’re using Bash, the solution is to use $’string’, for example: If you’re using pretty much any other shell, just insert the newline as-is in the string: Bash is pretty nice. It accepts more than just \n in the $” string. Here is an excerpt from the Bash manual page:

Shell Script Syntax Error: Unexpected End of File

Edit: Note that the original post has been edited since this answer was written and has been reformatted. You should look at the history to see the original formatting to understand the context for this answer. This error occurs often when you have mismatched structure – that is, you do not have matching double quotes, … Read more