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

Re: Shell script - insert newline into string

by Tony Wilson-4 :: Rate this Message:

Reply to Author | View in Thread

--- In nslu2-linux@..., Kumar Appaiah <a.kumar@...> wrote:

>
> 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
>


That works from the command line, but not in script!

string=`echo -e "A\nB\nCDE\nF"`
echo $string

output:
A B CDE F





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