Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 71339 - app-shells/bash-2.05b-r9 - parameter expansion with negative offset broken
Summary: app-shells/bash-2.05b-r9 - parameter expansion with negative offset broken
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All All
: High normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-15 16:36 UTC by Carsten Lohrke (RETIRED)
Modified: 2004-11-16 09:12 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carsten Lohrke (RETIRED) gentoo-dev 2004-11-15 16:36:33 UTC
The man page states: 

${parameter:offset:length}  <...>  If offset evaluates to a number less than zero, the value is used as an offset from the end of the value of parameter. 

This doesn't work. Trying it with an empty parameter reveals, that bash performs ${parameter:-word} instead. Didn't tried it with bash 3.x, but it's the same with a 2.x bash which on a Knoppix Iso.

Advanced Bash Scripting Guide reference tables:
http://www.tldp.org/LDP/abs/html/refcards.html#AEN16232
Comment 1 SpanKY gentoo-dev 2004-11-15 18:28:03 UTC
use ${blah:0:0-1}
Comment 2 SpanKY gentoo-dev 2004-11-15 18:28:28 UTC
err ${blah:0-1}
Comment 3 Carsten Lohrke (RETIRED) gentoo-dev 2004-11-16 03:16:20 UTC
No.

FOO="WORKS"
echo ${FOO:-4:4} 

should result in "ORKS"
Comment 4 SpanKY gentoo-dev 2004-11-16 06:10:04 UTC
i still say it's not a bug

the two forms have the exact same syntax and it's easier to trick the offset than it is to trick the ${var:-default} form

if you consider it a bug, convince upstream, because we're not going to change the behavior unless they do
Comment 5 Carsten Lohrke (RETIRED) gentoo-dev 2004-11-16 08:37:12 UTC
>the two forms have the exact same syntax and it's easier to trick the offset than it is to trick the ${var:-default} form

Exactly. Something like ${FOO:-2:2} is ambiguous, so my guess is, that the negative offset is not allowed anymore and they missed to fix the man page. It's sad, if you don't think that is a bug, and that it is better to provide either incorrect information or to ship a buggy bash (POV thing, I don't care), but damn - it's maintainers job to sort that out.
Comment 6 SpanKY gentoo-dev 2004-11-16 08:49:31 UTC
the manpage does not say exactly what said form is

they simply say 'if offset evaluates to a number less than zero'

$ FOO=WORKS
$ echo ${FOO:0-1}
S

doing ${FOO:-1} is ambigious, but they had to do something ... going the route they did makes more sense then going the opposite

as for it being 'the maintainers job to sort this out', there really isnt any 'incorrent information being shipped' nor is there a 'buggy bash' ... thus it's *your* problem to convince people otherwise :P

the ONLY thing i would change here is add a note under said section about such usage being ambigious
Comment 7 Carsten Lohrke (RETIRED) gentoo-dev 2004-11-16 09:12:30 UTC
Umm - now I got it. Confused /me learned something. Did not try your 0-1 sample before. Still don't think, that this bashism is well thought.

>thus it's *your* problem to convince people otherwise :P

That's why I don't stop commenting. I just like to get emails from you. ;p This time I have to admit that you're right.