Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.unix.programmer > #5191
| From | dave.gma+news002@googlemail.com.invalid (Dave Sines) |
|---|---|
| Newsgroups | comp.unix.programmer |
| Subject | Re: Bash 4.3.0 escape expansion |
| Date | 2014-03-09 13:21 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <0f6uuaxp62.ln2@perseus.wenlock-data.co.uk> (permalink) |
| References | (7 earlier) <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> <20140308115057.722@kylheku.com> |
Kaz Kylheku <kaz@kylheku.com> wrote:
> On 2014-03-08, Dave Sines <dave.gma+news002@googlemail.com.invalid> wrote:
[bash substitution expansion oddness]
> 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
[...]
> Then, here is another kicker. Suppose we turn the final \' into just '
>
> $ echo "${FOO//\'/'\\\'\}"
> > '
> > "
> > }
> > what are you waiting for me to close?
The final backslash escapes the closing brace so the trailing double
quote opens a new string. Close the double-quote, close the braces,
close the outer double-quote:
$ echo "${FOO//\'/'\\\'\}"
> "}"
If you meant:
$ echo "${FOO//\'/'\\\''}"
The final single-quote opens a new string. Close that, provide the
closing brace and then the double-quote:
$ echo "${FOO//\'/'\\\''}"
> '}"
[...]
> So we have to obey proper quoting syntax, and yet that quoting is not
> processed and stripped!
>
> $ echo "${FOO//\'/'\\'}"
> a'\'b'\'c
This was changed for bash 4.3 which now behaves like ksh and mksh.
echo "${FOO//\'/\'\\\'\'}"
Or:
echo "${FOO//"'"/"'\\''"}"
For bash versions prior to 4.3, either use the method posted by Ben
Bacarisse elsewhere in this thread or perform the substitution unquoted
(which requires assignment to an intermediate variable to avoid
problems with word splitting etc).
a=${FOO//\'/\'\\\'\'}
echo "$a"
Back to comp.unix.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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