View Full Version : newlines in shell

king vash
September 4th, 2009, 12:44 AM
I have a shell script which takes a string (with newlines in it) as a parameter. It then sends that to another program.

called like "sh printer.sh "Hello \n World"
when I use it later in the program the \n has been converted to a newline character. I need it to not echo with a newline character but with a "\n"

"echo $1" prints

were I want "Hello \n Wold".

any ideas?

September 4th, 2009, 12:53 AM
echo $1

Bash Works the way you want it to

echo $1

Sh does not.

Someone else may know exactly why this is.

king vash
September 4th, 2009, 02:30 AM
Thank you, that solved the problem!

September 4th, 2009, 03:47 AM
Instead of switching shells, consider using echo with single quotes to print the output literally:

echo 'bin \n my bash'

September 24th, 2009, 04:58 PM
This might work:

echo "Hello \\n World"