[Parameter substring expansion not work for negative offset]

2013-09-08 Thread hanzlik
Configuration Information:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-redhat-linux-gnu' 
-DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib  -D_GNU_SOURCE -DRECYCLES_PIDS 
-DDEFAULT_PATH_VALUE='/usr/local/bin:/usr/bin' -D_LARGEFILE_SOURCE 
-D_FILE_OFFSET_BITS=64 -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions 
-fstack-protector --param=ssp-buffer-size=4  -m32 -march=i686 -mtune=atom 
-fasynchronous-unwind-tables
uname output: Linux franta.hanzlici.cz 3.10.10-200.fc19.i686.PAE #1 SMP Thu Aug 
29 19:16:15 UTC 2013 i686 i686 i386 GNU/Linux
Machine Type: i686-redhat-linux-gnu

Bash Version: 4.2
Patch Level: 45
Release Status: release

Description:
As I understand bash man page, using negative offset in substring expansion
 ${parameter:offset} / ${parameter:offset:length}
then offset shoul be taken as offset from the parameter value string.
Thus, e.g. ${A:-1} or ${A:-1:1} should return last character from $A string.
But this construct return me all $A string.

Repeat-By:
$ A="abcd0"; E1=${A:-1:1}; E2=${A:-1}; echo "A=$A, E1=$E1, E2=$E2."
A=abcd0, E1=abcd0, E2=abcd0.

# I expect result E1==E2=="0", right?

Sorry if I made some mistake here.
With regards, Franta Hanzlik 



Re: [Parameter substring expansion not work for negative offset]

2013-09-09 Thread Frantisek Hanzlik
Greg Wooledge wrote:
> On Sun, Sep 08, 2013 at 11:21:56AM -0500, Dennis Williamson wrote:
>> The man page says "Note that a negative offset must be separated from the
>> colon by at least one space..."
> 
> Enclosing the negative offset in parentheses also works.
> 
> The reason you must use either parentheses or spaces between them is
> because ${parameter:-word} has another, completely different meaning.
> 
>   ${foo:-1}
> 
> will expand to the contents of `foo' if it is set and not empty, or the
> literal string `1' otherwise.


Messieurs,

please excuse my stupidity. Although I'm using bash relatively often
including 'use default value' construct (${parameter:-word}), in this
case I somehow not joined this together.

And my failure to properly read through man page I rather will not
comment...

Thanks, Franta Hanzlík