[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: escape strings in grub.cfg
From: |
Colin Watson |
Subject: |
Re: escape strings in grub.cfg |
Date: |
Mon, 12 Apr 2010 19:52:24 +0100 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
On Mon, Apr 12, 2010 at 12:23:01PM -0500, address@hidden wrote:
> On Sun, Apr 11, 2010 at 7:09 PM, Colin Watson <address@hidden> wrote:
> > On Sat, Apr 10, 2010 at 10:10:15PM +0100, Carles Pina i Estany wrote:
> >> +gettext_escape_double_quotes ()
> >> +{
> >> + echo -n $(gettext $@) | sed 's/\"/\\\"/'
> >> +}
> >
> > This is underquoted, and in any case the 'echo -n' is redundant since
> > gettext itself already writes to standard output and $() substitution
> > strips trailing newlines. $@ requires special treatment, and that sed
> > s/// command needs /g. With my suggestion, I'd recommend:
> >
> > gettext_quoted () {
> > gettext "$@" | sed "s/'/'\\\\''/g"
> > }
>
> I haven't tried it myself, but you just said the newline is stripped
> by $() and then took out the $(), seems like the newline would be
> present again.
In context, gettext_quoted would always be called from inside $(), so
this isn't a problem.
(In general I find that it's best to write shell functions such that
they emit trailing newlines on their output, and let the caller strip it
if necessary; this usually comes out quite naturally. Of course there
are exceptions.)
--
Colin Watson address@hidden