“echo -n” prints “-n”

There are multiple versions of the echo command, with different behaviors. Apparently the shell used for your script uses a version that doesn’t recognize -n. The printf command has much more consistent behavior. echo is fine for simple things like echo hello, but I suggest using printf for anything more complicated. What system are you … Read more

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

If you’re using Bash, the solution is to use $’string’, for example: $ STR=$’Hello\nWorld’ $ echo “$STR” # quotes are required here! Hello World If you’re using pretty much any other shell, just insert the newline as-is in the string: $ STR=’Hello > World’ Bash is pretty nice. It accepts more than just \n in … Read more