[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bash' code to store string of any characters containing pair of "" a
From: |
Greg Wooledge |
Subject: |
Re: Bash' code to store string of any characters containing pair of "" and '' at once |
Date: |
Sat, 21 Dec 2024 13:52:48 -0500 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
On Sat, Dec 21, 2024 at 09:56:15 -0800, Eric Pruitt wrote:
> On Sun, Dec 22, 2024 at 12:49:07AM +0700, Budi wrote:
> > How is Bash' code to store string of any characters should be containing
> > pair of "" and '' at the same time explicitly, being exact verbatim so,
> > ie. cannot be modified, escaped or etc, as expected from ordinary/naive
> > human writing), into a variable
>
> You need to escape one of the types of quotes. Double quotes is
> generally simpler:
>
> $ x="foo \"foo\" and 'bar' content"
> $ echo "$x"
> foo "foo" and 'bar' content
Only in this restricted case. Using double quotes as the outer layer
means you have to backslash-escape *lots* of other characters inside
the payload: double quotes, dollar signs, backticks, and backslashes
at the very minimum.
> Since you can't "\" escape inside of single quotes, you would end up
> with something more convoluted, like:
>
> $ x='foo "foo" and '"'"'bar'"'"' content'
'\'' is normally used, but '"'"' is also correct.