Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.unix.programmer > #5189

Re: Bash 4.3.0 escape expansion (was: Re: Escaping of line breaks for text replacement)

From Kaz Kylheku <kaz@kylheku.com>
Newsgroups comp.unix.programmer
Subject Re: Bash 4.3.0 escape expansion (was: Re: Escaping of line breaks for text replacement)
Date 2014-03-08 20:05 +0000
Organization Aioe.org NNTP Server
Message-ID <20140308115057.722@kylheku.com> (permalink)
References (8 earlier) <bntl15Fot2vU1@mid.individual.net> <kg2puaxk12.ln2@perseus.wenlock-data.co.uk> <bnua38FtboaU1@mid.individual.net> <hnkpuaxir5.ln2@perseus.wenlock-data.co.uk> <iseruax9c.ln2@perseus.wenlock-data.co.uk>

Show all headers | View raw


On 2014-03-08, Dave Sines <dave.gma+news002@googlemail.com.invalid> wrote:
> Dave Sines <dave.gma+news002@googlemail.com.invalid> wrote:
>> Markus Elfring <Markus.Elfring@web.de> wrote:
>
>>> Would it be useful to expand the clarification of corresponding
>>> implementation details to other mailing lists or issue trackers?
>> 
>> It may be a bug in bash 4.3, I've reported it to the bash bugs list.
>> The relevant part of the bug report follows:
>> 
>> Description:
>>        When invoked as sh, bash 4.3.0 doesn't interpret C-style escapes
>> within double-quoted substitution expansions ("${var/$'what'/ever}").
>
> There's a response (and a patch) available here:

What a mind-blowing coincidence!

I JUST used this Bash syntax (for the first time ever, I think!) merely
20 minutes ago, and ran into some issues with quotes.

I was trying to escape occurrences of ' with '\''.

I found two strange behaviors:

  $ echo $FOO
  a'b'c

Goal:   a'\''b'\''c

Not quite:

  $ echo "${FOO//\'/'\\\'\'}"
  a'\\'\'b'\\'\'c

Note how in the replacement pattern '\\\'\' the first quote is verbatim
and nicely goes through (and so it is not an activel quote), then there is an
escaped backslash \\ which However the two \' sequences each turn into \':
backslash is not a recognized escape for the quote.

Then, here is another kicker. Suppose we turn the final \' into just '

  $ echo "${FOO//\'/'\\\'\}"
  > '
  > "
  > }
  > what are you waiting for me to close?
  > ??
  > 
  > Ah screw this, Ctrl-C.
  > ^C

The syntax won't close no matter what you type. It does, however, evidently
espect the single quote (which came through the substitution verbatim!) to be
closed.

If we leave out a matching quote, Bash prompts us to close something:

  $ echo "${FOO//\'/'\\}"
  > 
  > ^C

If we add the closing quote, the opening and closing quotes are part of the
substitution!

So we have to obey proper quoting syntax, and yet that quoting is not
processed and stripped!

  $ echo "${FOO//\'/'\\'}"
  a'\'b'\'c

Or whatever ...

Back to comp.unix.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Escaping of line breaks for text replacement Markus Elfring <Markus.Elfring@web.de> - 2014-03-02 14:00 +0100
  Re: Escaping of line breaks for text replacement jt@toerring.de (Jens Thoms Toerring) - 2014-03-02 15:49 +0000
    Re: Escaping of line breaks for text replacement Markus Elfring <Markus.Elfring@web.de> - 2014-03-03 08:38 +0100
  Re: Escaping of line breaks for text replacement dave.gma+news002@googlemail.com.invalid (Dave Sines) - 2014-03-02 16:52 +0000
    Re: Escaping of line breaks for text replacement Kaz Kylheku <kaz@kylheku.com> - 2014-03-02 17:53 +0000
      Re: Escaping of line breaks for text replacement Kaz Kylheku <kaz@kylheku.com> - 2014-03-02 20:27 +0000
        Re: Escaping of line breaks for text replacement dave.gma+news002@googlemail.com.invalid (Dave Sines) - 2014-03-03 16:17 +0000
          Re: Escaping of line breaks for text replacement Kaz Kylheku <kaz@kylheku.com> - 2014-03-03 17:44 +0000
            Re: Escaping of line breaks for text replacement Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2014-03-04 13:30 +0000
    Re: Escaping of line breaks for text replacement Markus Elfring <Markus.Elfring@web.de> - 2014-03-02 20:50 +0100
      Re: Escaping of line breaks for text replacement dave.gma+news002@googlemail.com.invalid (Dave Sines) - 2014-03-03 16:52 +0000
    Re: Escaping of line breaks for text replacement Markus Elfring <Markus.Elfring@web.de> - 2014-03-03 09:24 +0100
    Re: Escaping of line breaks for text replacement Markus Elfring <Markus.Elfring@web.de> - 2014-03-03 12:55 +0100
      Re: Escaping of line breaks for text replacement dave.gma+news002@googlemail.com.invalid (Dave Sines) - 2014-03-03 17:02 +0000
        Re: Escaping of line breaks for text replacement Markus Elfring <Markus.Elfring@web.de> - 2014-03-06 12:02 +0100
          Re: Escaping of line breaks for text replacement dave.gma+news002@googlemail.com.invalid (Dave Sines) - 2014-03-06 18:51 +0000
            Re: Escaping of line breaks for text replacement Markus Elfring <Markus.Elfring@web.de> - 2014-03-06 20:48 +0100
              Re: Escaping of line breaks for text replacement dave.gma+news002@googlemail.com.invalid (Dave Sines) - 2014-03-06 22:59 +0000
                Re: Escaping of line breaks for text replacement Kaz Kylheku <kaz@kylheku.com> - 2014-03-07 06:38 +0000
                Re: Escaping of line breaks for text replacement Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-07 13:33 +0000
                Re: Escaping of line breaks for text replacement dave.gma+news002@googlemail.com.invalid (Dave Sines) - 2014-03-07 15:08 +0000
                Re: Escaping of line breaks for text replacement Markus Elfring <Markus.Elfring@web.de> - 2014-03-07 11:23 +0100
                Re: Escaping of line breaks for text replacement dave.gma+news002@googlemail.com.invalid (Dave Sines) - 2014-03-07 14:43 +0000
                Re: Escaping of line breaks for text replacement Markus Elfring <Markus.Elfring@web.de> - 2014-03-07 17:23 +0100
                Re: Escaping of line breaks for text replacement dave.gma+news002@googlemail.com.invalid (Dave Sines) - 2014-03-07 19:53 +0000
                Bash 4.3.0 escape expansion (was: Re: Escaping of line breaks for text replacement) dave.gma+news002@googlemail.com.invalid (Dave Sines) - 2014-03-08 12:26 +0000
                Re: Bash 4.3.0 escape expansion (was: Re: Escaping of line breaks for text replacement) Kaz Kylheku <kaz@kylheku.com> - 2014-03-08 20:05 +0000
                Re: Bash 4.3.0 escape expansion Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-09 03:48 +0000
                Re: Bash 4.3.0 escape expansion dave.gma+news002@googlemail.com.invalid (Dave Sines) - 2014-03-09 13:21 +0000
  Re: Escaping of line breaks for text replacement Kaz Kylheku <kaz@kylheku.com> - 2014-03-02 18:11 +0000
    Re: Escaping of line breaks for text replacement Markus Elfring <Markus.Elfring@web.de> - 2014-03-02 20:08 +0100
      Re: Escaping of line breaks for text replacement Kaz Kylheku <kaz@kylheku.com> - 2014-03-02 20:35 +0000
        Re: Which content should be escaped? Markus Elfring <Markus.Elfring@web.de> - 2014-03-03 10:30 +0100
          Re: Which content should be escaped? dave.gma+news002@googlemail.com.invalid (Dave Sines) - 2014-03-04 14:04 +0000
            Re: Which content should be escaped? Kaz Kylheku <kaz@kylheku.com> - 2014-03-04 17:32 +0000
  Re: Escaping of line breaks for text replacement Siri Cruz <chine.bleu@yahoo.com> - 2014-03-07 02:47 -0800

csiph-web