Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Substituting newline on a string
- X-seq: zsh-users 12994
- From: Javier Alvarado <quijotista@xxxxxxxxx>
- To: zsh-users@xxxxxxxxxx, Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>
- Subject: Re: Substituting newline on a string
- Date: Tue, 1 Jul 2008 10:57:07 -0700 (PDT)
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Received:X-Mailer:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Message-ID; b=nU4bBnWsXhEgIQd14aRKxHevviCPsF9p1vFGGykx8NbSiEMJbkKE5YSLVByCFlDaaNnB5KvGR0f1f7SMZp0PQ7SiyPa7iGlWP57SiBzlnRdcfoXpOfFbwTwrShG14QbgyTaTKG2hErgUkba1P31XMM/7q9IbrZd2kjlCg4Efn/I=;
- In-reply-to: <20080701174319.GO8450@xxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Reply-to: quijotista@xxxxxxxxx
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