bug-bash
[Top][All Lists]
Advanced

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

Bash 3.2.25 not expanding subscript...


From: Brad Diggs
Subject: Bash 3.2.25 not expanding subscript...
Date: Mon, 11 Feb 2008 19:52:24 -0600

Hello, 

I observed today that a bash feature that used to work 
in version 3.00.16(1) no longer works in version 3.2.25(1).
I have observed the bug on OpenSolaris snv_81 and Ubuntu
7.10 both of which run the same version 3.2.25(1).

In short the bug is the result of failure to expand the
subscript of an array if the subscript is a variable.
The following script should return a list of files with a 
preceding (File <#>: ).  However, it does not work that 
way because the integer variable (${d}) used in the subscript
of the array statement (FileList[${d}]=${File}) does not get 
properly expanded.

#!/bin/bash
declare -a FileList=('')
declare -i d=0

ls -1| while read File
do
   FileList[${d}]=${File}
   d=$((10#${d}+1))
done

d=0
while [[ ${d} -lt "${#FileList[*]}" ]]
do
   echo "File ${d}: ${FileList[${d}]}"
   d=$((10#${d} + 1))
done

I have found that this script works just fine with korn shell (ksh)
and bash version 3.00.16(1).  Just not bash 3.2.25(1).

When I reviewed the COMPAT and CHANGES files, the only items 
that looked remotely close to the problem that I have encountered 
are the following:

bash-3.0-alpha/bash3.0-beta1:
l.  When performing a compound array assignment, the parser doesn't
    treat words of the form [index]=value as assignments if they're
    the result of expansions.

bash-2.05b-alpha1/bash-2.05a-release:
jj. Array subscript expansion now takes place even when the array
    variable is unset, so side effects will take place.

If I was a programmer, I would try to propose a fix but alas I am not.
The best I can do is provide a re-producible use case.

References:
http://tiswww.case.edu/php/chet/bash/COMPAT
http://tiswww.case.edu/php/chet/bash/CHANGES

Thanks in advance,
Brad
-- 
The Zone Manager
http://TheZoneManager.COM
http://opensolaris.org/os/project/zonemgr





reply via email to

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