help-bash
[Top][All Lists]
Advanced

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

any plans for command substitution that preserves trailing newlines?


From: Christoph Anton Mitterer
Subject: any plans for command substitution that preserves trailing newlines?
Date: Mon, 31 May 2021 17:45:35 +0200
User-agent: Evolution 3.38.3-1

Hey.

I wondered whether there were any plans to implement proper support for
command substitutions that preserves trailing newlines?

If that was kinda coordinated with other POSIX sh compatible shells it
might ultimately even get standardised.



Seems there are plenty cases where this would be needed, e.g. take any
example of files that involve trailing newlines (I know... weird, but
possible):
some_dir=$'/tmp/./a\n///'

If such string shall get normalised like as in:
some_dir="$( realpath -sm "$some_dir" )"

in order to get:
some_dir=$'/tmp/a\n'
it already fails.



There seem to be a number of workarounds, using bash's read (which is
however not portable, as the options needed aren't POSIX) or using
sentinel values like:

foo="$( command ; rc=$?; printf 'x' ; exit $rc )"
#store rc if necessary
...

#remove the sentinel
foo=${foo%x}

but allegedly, these have numerous issues, too, depending on which
locales are used.



Cheers,
Chris.




reply via email to

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