Link to home
Start Free TrialLog in
Avatar of ibanja
ibanja

asked on

Why doesn't \n work in centos script

I have the following script:
$ cat ./test.sh
#!/bin/sh
var1="line1\nline2\n"
echo $var1

Open in new window


In Ubuntu I get the following when run:
$ ./test.sh
line1
line2

Open in new window


In Centos I get the following when run:
$ ./test.sh
line1\nline2\n

Open in new window


Why is it behaving differently?  I have tried replacing the:
#!/bin/sh
with:
#!/bin/bash

but no change.

Any insights appreciated.

Thanks,
Frank
ASKER CERTIFIED SOLUTION
Avatar of farzanj
farzanj
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It's your implementation of "echo"

Try echo -e

wmp
... or use ksh
The problem is with the echo command.  On CentOS it won't interpret the \n unless you use
echo -e $var1
Damn, beaten to it!  :-)
Avatar of ibanja
ibanja

ASKER

Thanks everyone.  Since farzanj got there first I gave him the points, but appreciate the responses.