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




Reply via email to