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
use ${blah:0:0-1}
err ${blah:0-1}
No. FOO="WORKS" echo ${FOO:-4:4} should result in "ORKS"
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
>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.
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
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.