[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bash substrings: wish for support for negative length (read till n f
From: |
Richard Neill |
Subject: |
Re: Bash substrings: wish for support for negative length (read till n from end) |
Date: |
Tue, 08 Jul 2008 05:43:14 +0100 |
User-agent: |
Thunderbird 2.0.0.12 (X11/20080306) |
Jan Schampera wrote:
> Richard Neill wrote:
>
>> $ echo ${stringZ:2: -1} #Wish: start at 2, read till
>> ERROR #1 before the end. i.e.
>> # cde
>>
>> $ echo ${stringZ: -3: -1} #Wish: start 3 back, read till
>> ERROR #1 before the end. i.e.
>
> Use (-1), i.e.
>
> $ echo ${stringZ:2:(-1)}
>
> See also
> http://bash-hackers.org/wiki/doku.php/syntax/pe#substring_expansion (at
> bottom of the section).
>
Dear Jan,
Thanks for your comment. I now understand why
echo ${stringZ:-1} is invalid, and it has to be
echo ${stringZ:(-1)} or echo ${stringZ: -1}
BUT, the example that you gave doesn't actually work; it returns with
an error:
-bash: (-1): substring expression < 0
My point is that, though the first parameter (offset) may be negative,
the second parameter (length) can only be positive. This is what would
be useful to change.
Thanks,
Richard