Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14360 > unrolled thread

Re: temp env allows variables that look like array subscripts

Started byChet Ramey <chet.ramey@case.edu>
First post2018-07-18 11:00 -0400
Last post2018-07-18 11:00 -0400
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: temp env allows variables that look like array subscripts Chet Ramey <chet.ramey@case.edu> - 2018-07-18 11:00 -0400

#14360 — Re: temp env allows variables that look like array subscripts

FromChet Ramey <chet.ramey@case.edu>
Date2018-07-18 11:00 -0400
SubjectRe: temp env allows variables that look like array subscripts
Message-ID<mailman.3761.1531926081.1292.bug-bash@gnu.org>
On 7/17/18 4:51 PM, Grisha Levit wrote:
> Usually, an assignment preceding a command that would create a
> variable with an invalid name is rejected and treated like a command
> name:
> 
> $ 1=X :
> bash: 1=X: command not found
> 
> But when the variable name looks (sort of) like an array subscript
> assignment, it is accepted and an oddly named variable is created:
> 
> $ f() { declare -p ${!var*}; }; var[0]=X var[@]=Y f
> declare -x var[0]="X"
> declare -x var[@]="Y"

They're valid assignment statements, and would be marked as such if
the command weren't there (the test for whether or not the subscript
is invalid comes after parsing). The question is what to do with them:

1. Reject them as invalid environment variable names.

2. Accept them as if they were valid assignment statements and create an
   array variable, rejecting the second assignment because it uses an
   invalid subscript, even though you can't export environment variables.

3. Create variables with the names as given, and just put them in the
   environment of commands invoked by `f', under the principle that POSIX
   says "applications shall be tolerant of such names [in the
   environment]f." Of course, that doesn't mean applications have to put
   garbage into the environment.

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/

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web