Page 1 of 1

Multi-Line Environment Variable

Posted: Tue Jan 15, 2013 5:37 pm
by becky
Hi,

I am trying to set an environment variable in a shell script so that it'll contain two lines of text. According to what I found on the web I think all I need to use a "\n" for a new line, but it doesn't seem to work.

For instance:

Code: Select all

[root@verticatest1 ~]# test="line1\nline2"
[root@verticatest1 ~]# echo $test
line1\nline2
I would like to see this:

Code: Select all

[root@verticatest1 ~]# echo $test
line1
line2
Anyone know how I can do this?

Re: Multi-Line Environment Variable

Posted: Tue Jan 15, 2013 6:59 pm
by JimKnicely
Becky,

You can use the -e switch of the echo command so that it treats escaped characters as special characters...

Code: Select all

[knice@vlab ~]# jim="line1\nline2"
[knice@vlab ~]# echo -e $jim
line1
line2
Does that help?

Re: Multi-Line Environment Variable

Posted: Wed Jan 16, 2013 5:34 pm
by becky
Awesome, thank Jim! That'll work for me!