help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Character clearance in either end front or back


From: Greg Wooledge
Subject: Re: Character clearance in either end front or back
Date: Thu, 8 Oct 2020 10:13:44 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Thu, Oct 08, 2020 at 10:07:26AM -0400, Alan D. Salewski wrote:
> On 2020-10-08 07:19:45, Greg Wooledge spake thus:
> > On Thu, Oct 08, 2020 at 12:00:06PM +0200, Reuti wrote:
> > > > Am 08.10.2020 um 08:06 schrieb Budi <budikusasi@gmail.com>:
> > > > but merely
> > > > clearing \\\  as in l=foo\\\
> > > > 
> > > > k=${%%\}
> > > 
> > > To remove all you will need a wildcard:
> > > 
> > > k=${l%%\\*}
> > 
> > No, that won't do it either.  You need an extended glob.
> > 
> > shopt -s extglob
> > k=${l%%+(\\)}
> > 
> > Without extended globs, you could do it using a loop that removes one
> > backslash at a time, but that's obviously going to be slower.
> 
> How about a two-step expansion[0]: generate (greedily) an exact
> substring of the trailing char(s) to remove (if any), and then slice
> it off (non-greedy):
> 
> k=${l%"${l##*[!\\]}"}
> 
> Not nearly as clean or clear as the extended glob approach, but
> works cross-shell.

Yes, that one is also correct.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]