On Wed, Aug 20, 2014 at 03:05:48PM +0200, [email protected] wrote:
> "If offset evaluates to a number less than zero, the value is used as
> an offset from the end of the value of parameter."
>
> Repeat-By:
> x="abcdef"; echo "${x:-2}"
> Expected: ef
> Got: abcdef
This is a result of the collision of two different syntaxes. Bash is
using the ${parameter:-word} ("Use Default Values") syntax here.
There are two ways to work around this:
${x: -2}
${x:(-2)}
Either one of these avoids the :- syntax ambiguity. I prefer the
parentheses myself.