bug-bash
[Top][All Lists]
Advanced

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

typeset -r prevents local variable of same name.


From: steveo
Subject: typeset -r prevents local variable of same name.
Date: Sun, 13 Feb 2011 15:17:25 -0500

Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-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 
-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=i386 -mtune=generic 
-fasynchronous-unwind-tables
uname output: Linux saturn.syslang.net 2.6.27.41-170.2.117.fc10.i686.PAE #1 SMP 
Thu Dec 10 10:48:30 EST 2009 i686 athlon i386 GNU/Linux
Machine Type: i386-redhat-linux-gnu

Bash Version: 3.2
Patch Level: 39
Release Status: release

Description:
        First, I already submitted this bug from work, but I didn't
 realize that the address I sent from would not be allowed to receive
 a response. This address will work fine.

If I declare a variable at the top scope using -r, it will prevent me
from declaring a local copy in a subroutine. This problem happens in
this version of bash as well as in bash4 under Fedora 14.

Repeat-By:
Here is a foo.sh that demonstrates the problem:

511 > cat foo.sh
#! /bin/bash
bar()
{
    typeset abc="$1"
    echo "abc:$abc"
}
typeset -r abc='Hello'
bar Goodbye
512 > ./foo.sh 
./foo.sh: line 4: typeset: abc: readonly variable
abc:Hello
513 > 

Here's another one that works and shows that top scope is the problem:

515 > cat foo2.sh 
#! /bin/bash
baz()
{
    typeset qwerty="$1"
    typeset -r abc=wahoo
    echo "qwertyabc:$qwerty$abc"
}
bar()
{
    typeset abc="$1"
    echo "abc:$abc"
}
bar Goodbye
baz ttt
515 > ./foo2.sh 
abc:Goodbye
qwertyabc:tttwahoo
516 > 

This makes it hard to define routines with local variables if you
don't know what variables are declared globally. The problem happens
with -r but does not seem to happen with -i or -a.

Am I missing something?

TIA

Steven W. Orr <address@hidden>

Fix:
        [Description of how to fix the problem.  If you don't know a
        fix for the problem, don't include this section.]



reply via email to

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