Re: [Help-bash] Transform strings with special characters so that the st
From:
Greg Wooledge
Subject:
Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?
Date:
Mon, 30 Mar 2015 09:47:16 -0400
User-agent:
Mutt/1.4.2.3i
On Mon, Mar 30, 2015 at 02:02:10PM +0100, Stephane Chazelas wrote:
> It's really strange that no shell, not even zsh or fish fixed
> that (removing all trailing newlines instead of just only one).
>
> The usual work around is to do
>
> var=$(cmd && echo .) && var=${var%?} && var=${var%?}
> (to remove only one newline)
>
> but that's obviously a pain.
In #bash we (de facto) agreed on this version:
var=$(cmd; printf x) var=${var%x}
Which is basically the same as yours, and I agree it's somewhat odd
that nobody ever came up with a shopt to stop $() stripping newlines.