On Fri, Jan 17, 2025, at 7:55 AM, Greg Wooledge wrote:
> On Thu, Jan 16, 2025 at 21:16:47 -0800, Wiley Young wrote:
>> But sentence six is an emphatic concern if you ask me, for how "character"
>> reads as "alphabetic character". Also how sentences five and six can be
>> read as contradictory.
>
> I really don't understand how you're reading this text.  Let's start by
> actually SHOWING the text in the email, so everyone can follow along.
>
>   1: This expansion modifies the case of alphabetic characters in parameter.

I find Wiley's main thesis -- that this sentence reads as a sort
of topic sentence that implicitly prefixes "alphabetic" to every
subsequent use of "character" -- to be pretty contrived.


>   2: The pattern is expanded to  produce a pattern just as in pathname
>      expansion.
>   3: Each character in the expanded value of parameter is tested against
>      pattern,  and, if  it  matches the pattern, its case is converted.
>   4: The pattern should not attempt to match more than one character.
>   5: The ^  operator converts lowercase letters matching pattern to uppercase;
>      the , operator converts matching uppercase letters to lowercase.
>   6: The  ^^  and ,, expansions convert each matched character in the
>      expanded value; the ^ and , expansions match  and  convert  only
>      the  first character in the expanded value.

But I do agree that sentences 5 and 6 could be clearer.  If you
already know how things work then it's not hard to understand what
these sentences mean to say, but if you don't then they might make
you scratch your head a bit.

"There are '^' and ',' operators, and also '^' and ',' expansions?
Are those different?  Is ${foo^x} using the '^' operator or the '^'
expansion?"


>> But why would it not alter the first alphabetic character if
>> the first character in the string is not alphabetic?
>
> Because that's not how it works.  It only tests the first character of
> the expanded parameter.  It says so in sentence 6.
>
>> That the first
>> character in a string would be an alphabetic one is an assumption, one that
>> seems to be in use.
>
> No.  Only alphabetic characters are eligible for modification.  It says
> so in sentence 1.
>
>> Neither assumption - that the first character would be
>> an alphabetic one, or that the algorithm would look for the first
>> alphabetic character - is clearly stated.
>
> Sentence 1 says that it must be alphabetic.  Sentence 6 says that only
> the first character is looked at (for , and ^).

These "assumptions" seem like a lot of projection to me.  The text
itself does not make these assumptions; it is Wiley who is making
assumptions about how the expansions work or were meant to work or
are meant to be used.  (Features are always designed with use cases
in mind, of course, but that's not something that needs to be in a
man page.)

That said, I think the two halves of sentence 6 do lend themselves
to being misunderstood:

        The `^^' and `,,' expansions convert each matched character
        in the expanded value; the `^' and `,' expansions match and
        convert only the first character in the expanded value.

Since the first clause says that "`^^' and `,,' [...] convert each
matched character", it's easy to jump to conclusions and misread
the second one as saying that "`^' and `,' [...] convert only the
first [matched] character".  Prior exposure to ${foo//x/y} vs.
${foo/x/y} (or sed 's/x/y/g' vs. sed 's/x/y/') no doubt encourages
this misreading.

Here's an attempt at clarification that restructures the section
and describes the behavior of ${foo^x} more explicitly.  It also
avoids the aforementioned confusion between the ^/, "operators"
and the ^/, "expansions".

        *Case modification.*  This expansion modifies the case of
        alphabetic characters in _parameter_.

        The _pattern_ is expanded to produce a pattern just as in
        pathname expansion.  The pattern should not attempt to match
        more than one character.  If _pattern_ is omitted, it is
        treated like a `?', which matches every character.

        The `^' expansion examines the first character in the
        expanded value of _parameter_; if that character matches
        _pattern_ and is lowercase, it is converted to uppercase.
        The `^^' expansion works similarly, but it converts every
        matching lowercase character in the expanded value.

        The `,' and `,,' expansions work like `^' and `^^',
        respectively, except that they convert matching uppercase
        characters to lowercase.

        [final paragraph left as-is]

-- 
vq

Reply via email to