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: Koichi Murase
Subject: Re: any plans for command substitution that preserves trailing newlines?
Date: Wed, 2 Jun 2021 09:05:41 +0900

2021年6月2日(水) 6:04 Christoph Anton Mitterer <calestyo@scientia.net>:
> > 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.

It is a different topic, but I doubt it. As far as I tested now,
$'...' is only supported by ksh family and zsh/bash. but ash/yash/posh
don't support it. Also, we may achieve a similar goal by "printf". The
standard is somewhat *minimal requirements* for new shells (and also
for old shells if new requirements are added), so I feel it is
unlikely.

> > So this is a problem that people encounter infrequently, one that has
> > a
> > solution that works 100% of the time in bash (your construct above
> > plus
> > temporarily setting LANG=C before removing the last character), and
> > doesn't
> > occur at all in the majority of situations (locales with UTF-8
> > encodings).
> >
> > Why is inventing new syntax the right approach?
>
> I guess no normal developer writing shell scripts will typically use
> these workarounds.

That is not related to whether the feature needs to be implemented by
a new syntax or implemented as a shell function. Maybe the problem is
that people don't use existing Bash libraries (including me). Maybe we
should promote the development and the use of shell script libraries
more.

> It's not even easy to spot all the places where it
> would be needed.
>
> Even if, it's quite impractical to constantly change LC_ALL

I don't think so. It's inevitable once one decides to deal with
arbitrary binary data.

> or read the
> value via IFS='' read -rd '' var < <(cmd).
>
> So in practise people will just ignore the issue - which arguably works
> for most cases - but there are likely corner cases where things break.
>
>
> 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.



reply via email to

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