On Mon, Jun 16, 2025 at 1:25 PM Lionel Cons <lionelcons1...@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//\"/}"