I have a shell script that I want to run on different Linux servers. When I run the echo command with the -e option and escape characters in a string, it does not execute as expected on the sh shell on Ubuntu 12.04 or Ubuntu 11.04. The two servers that we use for which I would like to run the script are working with CentOS 5.3 and Ubuntu 12.04. When I run the following command in bash on two servers, the expected result is returned:
$ echo -e "line1\nline2" line1 line2
When I run the same command in sh on a CentOS machine, the correct output is also generated. But when I run the command in sh Ubuntu 12.04 or 11.04, the following output is issued:
$ echo -e "line1\nline2" -e line1 line2
Interestingly, if I ran below in sh on Ubuntu, it will automatically interpret the escape characters.
$ echo "line1\nline2" line1 line2
The script must run in the sh shell and must be portable on different machines. Any decisions. I also really appreciate the link to some documents explaining why and how this happens.
source share