[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Add an XSI replacement for func_split_short_opt.
From: |
Eric Blake |
Subject: |
Re: [PATCH] Add an XSI replacement for func_split_short_opt. |
Date: |
Mon, 28 Jun 2010 16:37:48 -0600 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100621 Fedora/3.0.5-1.fc13 Lightning/1.0b2pre Mnenhy/0.8.2 Thunderbird/3.0.5 |
On 06/28/2010 04:19 PM, Ralf Wildenhues wrote:
> Hi Eric,
>
> thanks for the suggestion. I had considered the idea for a second, but
> failed to see the nontrivial half.
>
> * Eric Blake wrote on Mon, Jun 28, 2010 at 02:49:40PM CEST:
>> tmp=${1#?}
>> patt=
>> i=2
>> while test $i -lt ${#1}; do
>> patt="?$patt"
>
> If the parameter may be expected to be very long (which I don't think it
> will be) then
> func_append patt '?'
>
> would be useful here, and even if not, appending rather than prepending
> here helps with current bash.
>
>> i=$((i+1))
>> done
>> result=${tmp%$patt}
After thinking a bit more, this alternative should do the same job in
fewer lines of code and fewer temporary variables:
result=${1#?}
while test ${#result} -gt 1; do
result=${result%?}
done
Also, you have to be a bit careful:
$ tmp=a
$ echo ${tmp:2}
$ echo ${tmp#??}
a
that is, before trying to split off the first two bytes using XSI, you
must ensure that ${#1} has at least two bytes to be split in the first
place.
--
Eric Blake address@hidden +1-801-349-2682
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- [PATCH] Add an XSI replacement for func_split_short_opt., Gary V. Vaughan, 2010/06/27
- Re: [PATCH] Add an XSI replacement for func_split_short_opt., Ralf Wildenhues, 2010/06/27
- Re: [PATCH] Add an XSI replacement for func_split_short_opt., Gary V. Vaughan, 2010/06/27
- Re: [PATCH] Add an XSI replacement for func_split_short_opt., Eric Blake, 2010/06/28
- Re: [PATCH] Add an XSI replacement for func_split_short_opt., Eric Blake, 2010/06/29
- Re: [PATCH] Add an XSI replacement for func_split_short_opt., Gary V. Vaughan, 2010/06/29
- Re: [PATCH] Add an XSI replacement for func_split_short_opt., Ralf Wildenhues, 2010/06/29
- Re: [PATCH] Add an XSI replacement for func_split_short_opt., Gary V. Vaughan, 2010/06/29
- Re: [PATCH] Add an XSI replacement for func_split_short_opt., Ralf Wildenhues, 2010/06/29
- Re: [PATCH] Add an XSI replacement for func_split_short_opt., Eric Blake, 2010/06/29