[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
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 11:41:04 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Mon, Mar 30, 2015 at 03:39:58PM +0100, Stephane Chazelas wrote:
> 2015-03-30 09:47:16 -0400, Greg Wooledge:
> > In #bash we (de facto) agreed on this version:
> >
> > var=$(cmd; printf x) var=${var%x}
> >
> > Which is basically the same as yours
>
> That doesn't trim the one trailing newline you usually want to
> trim (which was the point of my two var=${var%?})
I don't know what your use case is, but in ours, we typically want to
preserve the exact output of the command. We don't arbitrarily want
to strip just one newline and leave the others.
Most often we use this when trying to read the contents of a file into
a variable:
content=$(cat file; printf x) content=${content%x}
which is sad, because it means we don't get to use $(< file) at all.
> and that fails
> to preserve the exit status of cmd though.
That's true.
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, (continued)
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Eduardo A . Bustamante López, 2015/03/25
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Eric Blake, 2015/03/25
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Eric Blake, 2015/03/25
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Chet Ramey, 2015/03/26
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Eric Blake, 2015/03/26
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Stephane Chazelas, 2015/03/29
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Greg Wooledge, 2015/03/30
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Stephane Chazelas, 2015/03/30
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Greg Wooledge, 2015/03/30
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Stephane Chazelas, 2015/03/30
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?,
Greg Wooledge <=
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Stephane Chazelas, 2015/03/30
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Stephane Chazelas, 2015/03/29
Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Stephane Chazelas, 2015/03/25