bug-bash
[Top][All Lists]
Advanced

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

Re: ${name} vs ${name-} with ${...//...}


From: Zachary Santer
Subject: Re: ${name} vs ${name-} with ${...//...}
Date: Mon, 16 Jun 2025 13:57:13 -0400

On Mon, Jun 16, 2025 at 1:25 PM Lionel Cons <lionelcons1972@gmail.com> wrote:
>
> Why do these two lines differ in output? ${name} and ${name-} should
> produce identical output if "name" exists as variable, or not?
>
> $  (name='bar" x' ; name="${name-//\"/}" ; printf "%q\n" "$name")
> 'bar" x'
> $  (name='bar" x' ; name="${name//\"/}" ; printf "%q\n" "$name")
> 'bar x'

You can't combine multiple forms of parameter expansion into one thing
like this. If name is unset, "${name-//\"/}" will do what the
${parameter-word} expansion does and expand to //"/.

If you want the combined effect of multiple forms of parameter
expansion, you're going to have to use multiple parameter expansions.
In your case, that would probably look like this:
name="${name-}"
name="${name//\"/}"



reply via email to

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