« Return to Thread: Shell script - insert newline into string

Re: Shell script - insert newline into string

by Kumar Appaiah-2 :: Rate this Message:

Reply to Author | View in Thread

On Sun, Jun 14, 2009 at 10:37:11AM -0000, Tony Wilson wrote:

>    Hi
>
>    I'm kind of embarrassed to ask this but I'm stuck!
>
>    I'm writing a shell script and need to insert a line feed into a string.
>    For some reason \n does not work on the NSLU2.
>    Nor does stuff like:
>
>    message="Subject:Test
>
>    Body of message here"
>
>    (ie newline within string)
>
>    Echo is not adding a new line when used to extend the string.

Here's one way:

[kumar@bluemoon ~] echo -e "A\nB\nCDE\nF"
A
B
CDE
F

i.e., the use of "-e" recoginized backslash escape sequences.

HTH.

Kumar
--
Kumar Appaiah

 « Return to Thread: Shell script - insert newline into string