Re: RFE: new syntax for command substitution to keep trailing newlines?
From:
Chet Ramey
Subject:
Re: RFE: new syntax for command substitution to keep trailing newlines?
Date:
Wed, 27 Jan 2021 15:33:00 -0500
User-agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.6.1
On 1/27/21 3:29 PM, Léa Gris wrote:
Now if you want to preserve all the newlines you can use an ASCII EOF
character (formerly Ctrl + Z) that is unlikely to be part of a legit string:
a=$(printf $'hello\n\n\n\32'); a=${a%$'\32'}; declare -p a
It doesn't matter what you use (besides a newline, of course). Just remove
a single character: a=${a%?}.
--
``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/