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: Wed, 2 Jun 2021 10:30:42 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.2

On 6/1/21 5:03 PM, Christoph Anton Mitterer wrote:
Hey again.

First perhaps, in the sense of a shell variable - what exactly is it's
content respectively a string?

Bytes.

3.267 Parameter doesn't says whether the content is a string in the
sense of 3.375 or a 3.92 Character String.

It depends on how and where it's used. Some operations work on
characters, which may be composed of multiple bytes, some (e.g., printf)
work on bytes.

On Tue, 2021-06-01 at 11:55 +0900, Koichi Murase wrote:
It seems the solution is also given there; set temporary LC_ALL=C

Which, if it would work - and it doesn't seem to for me - would be
quite ugly.

It would be no more `ugly' than inventing special new syntax for a limited
purpose.


Can someone (Chet?) confirm that the solution with adding *any*
character and removing it later on works (i.e. with any locale and
any
valid variable content, which is, AFAIU, anything but NUL)?

In a byte-oriented locale, using byte-oriented operations, you can remove
a byte from a string. In a locale with UTF-8 encoding you can remove a
byte with ASCII value < 128 from the end of a string, since it cannot be
part of a multibyte character.


Well that's basically may question in the beginning of that mail: What
is a variable intended to contain?

Only the user can speak to intent. Bash is happy to store arbitrary non-
null bytes in a variable's value.

But even the LC_ALL workaround doesn't work for me - in the sense that
even without I don't see a problem ^^

So you found it unnecessary. That's a strange definition of "not working" --
that you don't need to use it.

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