Multi-Line Environment Variable

Moderator: NorbertKrupa

Post Reply
User avatar
becky
Intermediate
Intermediate
Posts: 118
Joined: Sat Apr 28, 2012 11:37 am

Multi-Line Environment Variable

Post by becky » Tue Jan 15, 2013 5:37 pm

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?
THANKS - BECKSTER

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1822
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: Multi-Line Environment Variable

Post by JimKnicely » Tue Jan 15, 2013 6:59 pm

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?
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

User avatar
becky
Intermediate
Intermediate
Posts: 118
Joined: Sat Apr 28, 2012 11:37 am

Re: Multi-Line Environment Variable

Post by becky » Wed Jan 16, 2013 5:34 pm

Awesome, thank Jim! That'll work for me!
THANKS - BECKSTER

Post Reply

Return to “Vertica and the Operating System”