Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Substituting newline on a string



A-ha! using $'\n' does the trick. Didn't know about that one. Thanks!


--- On Tue, 7/1/08, Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx> wrote:

> From: Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>
> Subject: Re: Substituting newline on a string
> To: zsh-users@xxxxxxxxxx
> Date: Tuesday, July 1, 2008, 10:43 AM
> Javier Alvarado <quijotista@xxxxxxxxx>:
> > I have a seemingly trivial problem that I have not be
> able to solve.
> > How do I replace a newline in a string with somethinge
> else, like '
> > ' (or better yet '\n')?
> > 
> > I've tried 
> > 
> > cmd=${1/$/ /}
> > cmd=${1/\n/ /}
> > cmd=${1/\r/ /}
> 
> How about this?
> 
> [snip]
> zsh% foo=$'bar\nbaz'
> zsh% printf '%s\n' $foo
> bar
> baz
> zsh% printf '%s\n'
> ${foo//$'\n'/\\n}
> bar\nbaz
> [snap]
> 
> Regards, Frank
> 
> -- 
> In protocol design, perfection has been reached not when
> there is
> nothing left to add, but when there is nothing left to take
> away.
>                                                   -- RFC
> 1925



Messages sorted by: Reverse Date, Date, Thread, Author