[Top][All Lists]

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

Re: Negative offsets in variable substitution

From: Chris F.A. Johnson
Subject: Re: Negative offsets in variable substitution
Date: Tue, 25 Jan 2005 15:30:13 -0500 (EST)

On Tue, 25 Jan 2005, Bob Dowling wrote:

Version of bash:        2.05b.0(1)-release

Problem duplicated on AMD64/SuSE9.1 GNU Linux and Apple G5/MacOS 10.3.6. Both ship wit the same version of bash as given above.

"man bash" says in the Parameter Expansion section under Substring Expansion (${parameter:offset:length}) that "[i]f offset evaluates to a number less than zero, the value is used as an offset from the end of the value of parameter."

However, experience suggests otherwise:

$ xyz='abcdefghijkl'
$ echo ${xyz}
$ echo ${xyz:3}         # Positive offset - OK
$ echo ${xyz:-3}        # Negative offset - Not OK

I don't know whether this is a bug in the manual page or the bash program. Or in my understanding of the manual page.

   Take a look at the other parameter expansions (and what :- means).

$ xyz=
$ echo ${xyz:-3}
$ echo ${xyz:-3:1}
$ xyz=abcdefghijkl
$ echo ${xyz: -3}
$ echo ${xyz: -3:1}

        Chris F.A. Johnson                      http://cfaj.freeshell.org
                Everything in moderation -- including moderation

reply via email to

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