bug-bash
[Top][All Lists]
Advanced

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

Re: rewriting a readonly var should exit


From: John McKown
Subject: Re: rewriting a readonly var should exit
Date: Tue, 15 Dec 2015 08:35:22 -0600

Are you running BASH in POSIX mode? That's a option.

Example:

[tsh009@it-johnmckown-linux junk]$ cat ro.sh
#!/bin/bash
readonly x="x"
x="y"
echo "sno"
[tsh009@it-johnmckown-linux junk]$ ./ro.sh 
./ro.sh: line 3: x: readonly variable
sno
[tsh009@it-johnmckown-linux junk]$ vim ro.sh
[tsh009@it-johnmckown-linux junk]$ cat ro.sh
#!/bin/bash
set -o posix
readonly x="x"
x="y"
echo "sno"
[tsh009@it-johnmckown-linux junk]$ ./ro.sh
./ro.sh: line 4: x: readonly variable
[tsh009@it-johnmckown-linux junk]$ 



On Tue, Dec 15, 2015 at 5:12 AM, Aurelien ROUGEMONT <beorn@gandi.net> wrote:
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE_CONFIG_H   -I.  -I../. -I.././include -I.././lib
-D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector-strong -Wformat
-Werror=format-security -Wall
uname output: Linux clamavsig1 3.16.0-4-amd64 #1 SMP Debian
3.16.7-ckt11-1+deb8u6 (2015-11-09) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.3
Patch Level: 30
Release Status: release

Description:
        in the posix shell specification [1] when a script tries to to
overwrite a readonly variable it should crash the script.

Repeat-By:
        #!/bin/bash
        readonly rovar="goodvalue"
        rovar="badvalue"
        echo "You should not see this message"

Fix:
        the bash interpreter should exit when the readonly var is being asked
for an overwrite



[1]
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_01



--
 Aurelien                                  Domain Name Registrar
   \o/                                     Hosting For Geeks and more...
    Gandi.net                                  No Bullshit !




--

Schrodinger's backup: The condition of any backup is unknown until a restore is attempted.

Yoda of Borg, we are. Futile, resistance is, yes. Assimilated, you will be.

He's about as useful as a wax frying pan.

10 to the 12th power microphones = 1 Megaphone

Maranatha! <><
John McKown

reply via email to

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