ibanja
asked on
Why doesn't \n work in centos script
I have the following script:
$ cat ./test.sh
In Ubuntu I get the following when run:
In Centos I get the following when run:
Why is it behaving differently? I have tried replacing the:
#!/bin/sh
with:
#!/bin/bash
but no change.
Any insights appreciated.
Thanks,
Frank
$ cat ./test.sh
#!/bin/sh
var1="line1\nline2\n"
echo $var1
In Ubuntu I get the following when run:
$ ./test.sh
line1
line2
In Centos I get the following when run:
$ ./test.sh
line1\nline2\n
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
... or use ksh
The problem is with the echo command. On CentOS it won't interpret the \n unless you use
echo -e $var1
echo -e $var1
Damn, beaten to it! :-)
ASKER
Thanks everyone. Since farzanj got there first I gave him the points, but appreciate the responses.
Try echo -e
wmp