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:40:53 -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:
On Tue, 2021-06-01 at 09:26 -0400, Chet Ramey wrote:
I wondered whether there were any plans to implement proper support
for
command substitutions that preserves trailing newlines?

"Proper" is doing a lot of work in ths sentence.

What do you mean? That would be much work to get it implemented in the
shell?

I interpreted it to mean "appropriate" or "necessary." I don't think it's
either of those things.


That implies it's something that people want to standardize. I
haven't
seen any evidence of that.

And there is no guarantee it would ever happen. But at least with e.g.
$'...' strings it seems to work and POSIX might sooner or later
standardise it.

Maybe. I'm just skeptical of its value, given that ways to accomplish the
task already exist.

I just though it's a better chance to get it standardised if
implementations already have something like it - and not the other way
round.

That's certainly true.

Why is inventing new syntax the right approach?

I guess no normal developer writing shell scripts will typically use
these workarounds. It's not even easy to spot all the places where it
would be needed.

So we should invent something new because nobody will use the existing
methods? Why would they change to use a new method, if they can't spot
the places where it's needed now?


Even if, it's quite impractical to constantly change LC_ALL or read the
value via IFS='' read -rd '' var < <(cmd).

As opposed to changing scripts to use some syntax that doesn't yet exist?


Just imagine a script should delete a file, the path is e.g. previously
normalised with realpath or maybe one just gets the basename first.

If the file had a trailing newlines in it names the best that can
happen is that the rm simply fails - or in the worst case another file
of the same name (but without the trailing newlines) is taken.

If files with trailing newlines are common in your environment, wouldn't
you think that scripts to accommodate them would already use one of the
existing methods?

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