bug-bash
[Top][All Lists]
Advanced

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

Re: `${PARAMETER:OFFSET}' does not work for negative offset


From: Greg Wooledge
Subject: Re: `${PARAMETER:OFFSET}' does not work for negative offset
Date: Fri, 12 Feb 2016 08:29:03 -0500
User-agent: Mutt/1.4.2.3i

On Fri, Feb 12, 2016 at 09:22:21AM +0100, Ulrich Windl wrote:
>     "X=ABC; echo ${X:-2}" outputs "ABC", and not "BC"

When using a negative index/offset, you have to separate it from the
colon so that it is not interpreted as a ${var:-default} substitution.

There are many ways to write it:

  ${x: -2}
  ${x:(-2)}
  ${x:0-2}
  offset=-2; ${x:offset}
  ...

I prefer ${x:(-2)} myself, but they are all valid.



reply via email to

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