[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: any plans for command substitution that preserves trailing newlines?
From: |
Alex fxmbsw7 Ratchev |
Subject: |
Re: any plans for command substitution that preserves trailing newlines? |
Date: |
Wed, 26 Jan 2022 00:35:58 +0100 |
.. is called mapfile
u mapfile -d '' and restore \0's on usage of the resulting array
On Mon, May 31, 2021, 17:46 Christoph Anton Mitterer <calestyo@scientia.net>
wrote:
> 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.
>
>
>
- Re: any plans for command substitution that preserves trailing newlines?, (continued)
- Re: any plans for command substitution that preserves trailing newlines?, Christoph Anton Mitterer, 2022/01/26
- Re: any plans for command substitution that preserves trailing newlines?, Chet Ramey, 2022/01/26
- Re: any plans for command substitution that preserves trailing newlines?, Christoph Anton Mitterer, 2022/01/26
- Re: any plans for command substitution that preserves trailing newlines?, Chet Ramey, 2022/01/26
- Re: any plans for command substitution that preserves trailing newlines?, Christoph Anton Mitterer, 2022/01/26
- Re: any plans for command substitution that preserves trailing newlines?, Chet Ramey, 2022/01/27
- Re: any plans for command substitution that preserves trailing newlines?, Christoph Anton Mitterer, 2022/01/27
- Re: any plans for command substitution that preserves trailing newlines?, Chet Ramey, 2022/01/28
- Re: any plans for command substitution that preserves trailing newlines?, Christoph Anton Mitterer, 2022/01/28
- Re: any plans for command substitution that preserves trailing newlines?, Chet Ramey, 2022/01/29
Re: any plans for command substitution that preserves trailing newlines?,
Alex fxmbsw7 Ratchev <=
Re: any plans for command substitution that preserves trailing newlines?, Alex fxmbsw7 Ratchev, 2022/01/25