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

Re: Substituting newline on a string



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