help-bash
[Top][All Lists]
Advanced

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

Re: any plans for command substitution that preserves trailing newlines?


From: Chet Ramey
Subject: Re: any plans for command substitution that preserves trailing newlines?
Date: Sat, 29 Jan 2022 16:40:00 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.4.1

On 1/28/22 8:44 PM, Christoph Anton Mitterer wrote:

On Fri, 2022-01-28 at 11:19 -0500, Chet Ramey wrote:
It's not good form to force your own locale on the user, who might
not
even have it installed. So some shells dodge the question entirely:
you get
what you got when the shell started.

Others, like bash, treat everything as
multibyte characters whose interpretation is subject to the current
locale.

You mean if one has a fixed string like:
foo="b€r"
and changed the locale before, bash would parse "foo" still with the
old, but "b€r" with the new locale?

No. It means that word consists of a series of (possibly multibyte)
characters, and those characters are interpreted based on the locale at
parsing and execution time. You're not going to have trouble with the
`foo=' differing between locales, but the multibyte character corresponding
to the euro symbol in one locale may not correspond to the same symbol in a
different locale. So the bytes will probably be the same; the output of
`echo "$foo"' might differ.


That's what I'd have followed from POSIX' wording:

"Changing the value of LC_CTYPE after the shell has started shall not
affect the lexical processing of shell commands in the current shell
execution environment or its subshells."

That bit with lexical processing of commands isn't really intended to
refer to this aspect of processing; the above is going to be an assignment
statement (ASSIGNMENT_WORD) in any locale.

The processing part is mostly, as I think I said in an earlier message,
about <blank>s and other metacharacters and how the shell breaks input into
tokens and parses them.

I would argue that if you change LC_CTYPE in a script, you intend for the
new locale to affect command execution, like for pattern matching.


It gets tricky. Say you unset LC_ALL, which the shell inherited from
the
environment, and that `unshadows' a value of, for instance, LC_CTYPE
that
the shell also inherited in its environment. Child processes will see
a
different value for that category than you may have intended.

Sure that's clear,...but for that reason we only change the locale
around the substitution, and we only unset LC_ALL afterwards, if it was
already unset before.

Yes, but we were talking about temporarily controlling the locale a command
sees, in the general case, and addressing your "(even those that I don't
touch)" comment.

--
``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/



reply via email to

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