[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: |
Chet Ramey |
Subject: |
Re: How does quote removal work with alternative forms of parameter expansion? |
Date: |
Wed, 29 May 2024 16:35:28 -0400 |
User-agent: |
Mozilla Thunderbird |
On 5/26/24 8:38 PM, Philippe Cerfon wrote:
An interesting behavior is that
the «"» inside the double quotations toggles the expansion behavior
(as if the first " inside double quotes is paired with the opening
double quotation, and the second " inside double quotes is paired with
the closing double quotation):
This is the historical Bourne shell behavior, which ksh93 preserves for
historical compatibility.
Why does:
$ bar='1 2'
$ printf '%s\n' "${unset_var:-"$bar"}"
then result in:
1 2
and not:
1
2
Because all the modern shell authors thought that aspect of the old Bourne
shell behavior was not worth preserving. Everyone agrees the double quotes
surrounding the expansion should inhibit word splitting. We just disagree
on some aspects of what to do about double quotes appearing on the rhs of
the operator.
You have to do something: either the double quotes on the rhs are special,
in which case they have meaning, affect processing of the characters they
enclose, and are removed, or they aren't, in which case they don't affect
processing but are somehow removed anyway.
In the early days we were a little more concerned about original Bourne
shell compatibility, because we wanted bash to run on 4.3 BSD, which
still used the 7th edition sh. So the historical bash behavior is kind of
a compromise.
--
``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/
OpenPGP_signature.asc
Description: OpenPGP digital signature
Re: How does quote removal work with alternative forms of parameter expansion?, Koichi Murase, 2024/05/26