|
From: | Eric Blake |
Subject: | Re: [Help-bash] Is there a way to not to remove tailing newline in command substitution? |
Date: | Wed, 12 Dec 2018 21:57:56 -0600 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 |
On 12/12/18 9:32 PM, Peng Yu wrote:
Hi, Sometimes, it may be better to preserve the trailing newline in a command substitution. Is there a way to do so? Thanks.
Yes. Forcefully end your command substitution with a non-newline sentinel, then strip it after the fact:
x=$(echo $'\n'.) x=${x%?} -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
[Prev in Thread] | Current Thread | [Next in Thread] |