bug-bash
[Top][All Lists]
Advanced

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

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


From: Chet Ramey
Subject: Re: ${name} vs ${name-} with ${...//...}
Date: Mon, 16 Jun 2025 14:01:41 -0400
User-agent: Mozilla Thunderbird

On 6/16/25 12:51 PM, Lionel Cons wrote:
Why do these two lines differ in output? ${name} and ${name-} should
produce identical output if "name" exists as variable, or not?

They're not the same expansion, and the example you're using is not the
same as your question.

$  (name='bar" x' ; name="${name-//\"/}" ; printf "%q\n" "$name")
'bar" x'

In this expansion, you get the unsplit value of `name', since it's
set, and print it.

$  (name='bar" x' ; name="${name//\"/}" ; printf "%q\n" "$name")
'bar x'

In this expansion, you remove the double quote and print the result.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

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