help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How does quote removal work with alternative forms of parameter expa


From: Greg Wooledge
Subject: Re: How does quote removal work with alternative forms of parameter expansion?
Date: Sun, 26 May 2024 19:38:10 -0400

On Sun, May 26, 2024 at 11:33:12PM +0200, Philippe Cerfon wrote:
> But above with ##, single quotes *did* prevent expansion. Why not here:
> 
> x="${1:-'$bar'}"  |  bash x.sh ""   |   'expanded'  => why not quote
> removal, why expansion?

hobbit:~$ set -- foo; bar=BAR
hobbit:~$ echo "${1:-'$bar'}"
foo
hobbit:~$ set --
hobbit:~$ echo "${1:-'$bar'}"
'BAR'

OK, I don't know.  I don't try to figure out all of the corner cases.
What I try to do is figure out how to write scripts that actually work.

So, the question becomes "What do you want to do?"

Once we know what you want to do, then we can try to come up with code
that does it, in the current bash version, or in every bash version, or
in every POSIX-sh-derived shell.

In some cases, the best way to write code that includes literal single
or double quotes in the output (or in patterns to be matched) is to put
those characters into variables, and use variable expansions.

As an example of that, see <http://mywiki.wooledge.org/CodeInjection>:

    # Use "sh quoting" for this example.  Other forms are possible,
    # depending on the client and server configuration.
    q=\' b=\\
    ssh user@host bash -s "'${argument//$q/$q$b$q$q}'" <<'EOF'
    long and complicated script
    goes here
    EOF



reply via email to

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