bug-bash
[Top][All Lists]
Advanced

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

Re: It is possible to remove the readonly attribute from {BASH, SHELL}OP


From: Chet Ramey
Subject: Re: It is possible to remove the readonly attribute from {BASH, SHELL}OPTS
Date: Wed, 31 Jan 2024 14:09:48 -0500
User-agent: Mozilla Thunderbird

On 1/24/24 7:06 PM, Emanuele Torre wrote:
I recently discovered that it is possible to set attributes on readonly
variables

You've been able to set attributes on readonly variables forever. Even the
historical Bourne shell allowed you to export readonly variables.


   $ declare -p PPID
   declare -ir PPID="759437"
   $ declare -l PPID
   $ declare -p PPID
   declare -irl PPID="759437"

I noticed SHELLOPTS and BASHOPTS among the default readonly variables
set by bash.
They are modified by bash whenever you set a set option or shopt.

I tried setting the -i attribute on them, and got this result:

Well, is this a "my arm hurts when I do this" problem, or should bash
restrict the types of attributes that can be set on readonly variables?

The arithmetic syntax error caused by trying to assign the new list of
options to SHELLOPTS prevents bash from changing its value, and
re-adding the readonly attribute to SHELLOPTS.

That's clearly a problem that needs to be fixed.

Then SHELLOPTS can be modified, and unset freely. :-)

The same is possible with BASHOPTS.

Sure, it's a problem that you can do it, but it's not really harmful.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/




reply via email to

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