Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 115142 - bash-3.1 errors when declaring multiple arrays on one line
Summary: bash-3.1 errors when declaring multiple arrays on one line
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High critical (vote)
Assignee: Gentoo's Team for Core System packages
URL: http://lists.gnu.org/archive/html/bug...
Whiteboard:
Keywords:
: 115150 115187 115257 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-12-10 18:15 UTC by Paul Taylor
Modified: 2006-01-11 11:33 UTC (History)
21 users (show)

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 Paul Taylor 2005-12-10 18:15:08 UTC
Several scripts are attempting to initialise variables using 'var=()' which
generates syntax errors e.g.

# rc-status
/lib/rcscripts/sh/rc-daemon.sh: line 328: syntax error near unexpected token `('
/lib/rcscripts/sh/rc-daemon.sh: line 328: `     local -a RC_DAEMONS=()
RC_PIDFILES=()'
/bin/rc-status: line 167: update_service_status: command not found
/bin/rc-status: line 167: update_service_status: command not found
/bin/rc-status: line 167: update_service_status: command not found
[snip]

This causes many of the init scripts to fail, resulting in broken net
configurations etc.

I believe these initialisations should be 'var=""'.

The affected scripts that I've found so far are:
   /etc/init.d/net.eth0
   /etc/init.d/runscript.sh
   /lib64/rcscripts/net.modules.d/iwconfig
   /lib64/rcscripts/sh/rc-daemon.sh
Comment 1 Paul Taylor 2005-12-10 18:17:47 UTC
Addendum - for 32-bit platforms, substitute /lib/rcscripts for /lib64/rcscripts.
Comment 2 Paul Taylor 2005-12-10 19:00:43 UTC
After trying to rollback to earlier versions of baselayout, it appears the
problem is caused by bash-3.1; masking this and re-emerging bash-3.0 fixes the
scripts.

(While simply changing the variable initialisation removed the syntax error
messages, the scripts didn't work properly e.g. /etc/init.d/net.lo attempts to
use DHCP, and fails.)
Comment 3 Jakub Moc (RETIRED) gentoo-dev 2005-12-11 01:59:38 UTC
*** Bug 115150 has been marked as a duplicate of this bug. ***
Comment 4 André Terpstra 2005-12-11 02:55:44 UTC
Problem and workaround confirmed here on gentoo 2.4 / athlon xp. Note that the
version number is actually bash-3.0-r14.
Comment 5 Ed Catmur 2005-12-11 04:15:27 UTC
Initialisations are correct; it's a parsing error with two or more array
variables declared in the same statement. Splitting the array initialisations
onto one per line is a workaround.
Comment 6 Jakub Moc (RETIRED) gentoo-dev 2005-12-11 05:20:57 UTC
*** Bug 115187 has been marked as a duplicate of this bug. ***
Comment 7 Jakub Moc (RETIRED) gentoo-dev 2005-12-11 06:43:21 UTC
bash-3.1 is in package.mask now...
Comment 8 Matteo Azzali (RETIRED) gentoo-dev 2005-12-11 07:30:55 UTC
hum, same here?
#/etc/init.d/iptables restart

/lib/rcscripts/sh/rc-daemon.sh: line 328: syntax error near unexpected token `('
/lib/rcscripts/sh/rc-daemon.sh: line 328: `     local -a RC_DAEMONS=()
RC_PIDFILES=()'
Comment 9 Jakub Moc (RETIRED) gentoo-dev 2005-12-11 07:35:41 UTC
(In reply to comment #8)
> hum, same here?

Hum, there's really no need to post 'me too' comments. Downgrade your bash.
Comment 10 SpanKY gentoo-dev 2005-12-11 09:51:31 UTC
works:
func() { local -a foo=() ; }

fails:
func() { local -a foo=() bar=() ; }
Comment 11 André Terpstra 2005-12-11 11:55:55 UTC
So this has nothing to do with baselayout, that was just a coincidence. Good the
bug tile has been modified to clarify this.

About bash 3.1: I guess this behaviour is intentional? Will all offending
scripts be rewritten?
Comment 12 Phil Richards 2005-12-11 11:59:43 UTC
There is no indication in the bash man page that multiple assignments of arrays
are forbidden, and, indeed, this is the case...

Following on from comment #10:

func() { local -a foo=() bar=(1); }

works.  Fairly obviously a (upstream?) bug.

Then again, I'm not sure why the variables are being initialised to () anyway. 
Doesn't seem necessary since "local -a foo bar" would have the same effect.

Phil
Comment 13 SpanKY gentoo-dev 2005-12-11 17:58:18 UTC
> func() { local -a foo=() bar=(1); }
> 
> works.  Fairly obviously a (upstream?) bug.

that doesnt work, sounds like you downgraded to bash-3.0 and then ran the test
Comment 14 SpanKY gentoo-dev 2005-12-11 18:35:32 UTC
*** Bug 115257 has been marked as a duplicate of this bug. ***
Comment 15 Zac Slade 2005-12-12 12:26:02 UTC
Bash 3.0 behavior: 
foo() { local -a BAR=() BAR1=(); } -- Works 
foo() { local BAR= BAR1=; } -- Works 
 
Bash 3.1 behavior: 
foo() { local -a BAR=() BAR1=(); } -- Error: 
bash: syntax error near unexpected token `(' 
foo() { local BAR= BAR1=; } -- Works 
 
So bash 3.1 is treating -a differently.  When creating local arrays it doesn't 
allow more than one declaration on a line.  When creating just local variables 
you can create more than one on a line in both versions. 
 
I'm not convinced it's an upstream bug.  There is an obvious difference, but it 
may be the intended behavior is to only allow one array to be declared at a 
time.  The documentation needs to be cleared up on this issue. 
 
Comment 16 SpanKY gentoo-dev 2005-12-12 12:32:24 UTC
the documentation is actually pretty clear

local [option] [name[=value] ...]
   For each argument, a local variable named name is created, and assigned value.  The option can be any of the options accepted by declare.

and under declare we read:
   -a     Each name is an array variable (see Arrays above).

so the documentation *clearly* states that defining multiple arrays
(i.e. using the -a option) is acceptable
Comment 17 Lars Wendler (Polynomial-C) (RETIRED) gentoo-dev 2005-12-21 15:44:04 UTC
Hi,

Chet finally released a patch:
ftp://ftp.cwru.edu/pub/bash/bash-3.1-patches/bash31-001

Tried it with an ebuild in my overlay and the problem is gone.

Cheers Poly
Comment 18 SpanKY gentoo-dev 2005-12-21 16:17:28 UTC
thanks, bash-3.1-r1 in portage
Comment 19 Milosz Kosobucki 2005-12-24 06:14:41 UTC
But even with patch bash-3.1 doesn't read the configuration of the net interface. I have eth0 with hard configured ip, netmask and so, and when i start the iface it says that no configuration is available and assumes dhcp. It behaves just like /etc/conf.c/net.eth0 didn't exist or was empty.
Comment 20 Dead Schorsch 2005-12-24 06:37:41 UTC
Even worse, it breaks a lot of startup-scripts to (but without "noise" this time) and was therefor pulled back, obviously