[Top][All Lists]

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

Re: coproc and existing variables

From: Chet Ramey
Subject: Re: coproc and existing variables
Date: Thu, 19 May 2016 10:52:08 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:45.0) Gecko/20100101 Thunderbird/45.1.0

On 5/17/16 5:14 PM, Grisha Levit wrote:
> On Sun, Apr 24, 2016 at 2:17 PM, Chet Ramey <address@hidden
> <mailto:address@hidden>> wrote:
>     it seems reasonable to follow printf/read/mapfile and not overwrite read-
>     only variables used as coproc names.  getopts will remain an outlier.
> getopts can probably benefit from a nameref check too, otherwise it can be
> exploited to unset arbitrary readonly variables.
> |$ declare -r RO=foo; declare -n OPTARG; getopts x x; declare -p RO bash:
> declare: RO: not found |

Existing practice across several shells is that getopts unsets OPTARG
whether or not it's readonly (and, at least in the case of ksh93/mksh,
does not honor any readonly setting at all, even on assignment), so it
would probably be best to just unset OPTARG when an unknown option is
encountered without following any nameref chain.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

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