bug-bash
[Top][All Lists]
Advanced

[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: Eric Pruitt
Subject: Re: Bash' code to store string of any characters containing pair of "" and '' at once
Date: Sat, 21 Dec 2024 09:56:15 -0800

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

Since you can't "\" escape inside of single quotes, you would end up
with something more convoluted, like:

$ x='foo "foo" and '"'"'bar'"'"' content'
$ echo "$x"
foo "foo" and 'bar' content

Alternatively:

$ x='foo "foo" and '"'bar' content"
$ echo "$x"
foo "foo" and 'bar' content

Eric



reply via email to

[Prev in Thread] Current Thread [Next in Thread]