bug-bash
[Top][All Lists]
Advanced

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

certain strings both legal and illegal as associative array keys


From: vampyrebat
Subject: certain strings both legal and illegal as associative array keys
Date: Sun, 01 Mar 2015 00:05:53 -0600

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: i686-pc-linux-gnu-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I. -I./include -I. -I./include -I./lib  
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
 -DSTANDARD_UTILS_PATH='/bin:/usr/bin:/sbin:/usr/sbin' 
-DSYS_BASHRC='/etc/bash/bashrc' -DSYS_BASH_LOGOUT='/etc/bash/bash_logout' 
-DNON_INTERACTIVE_LOGIN_SHELLS -DSSH_SOURCE_BASHRC -O2 -march=native -pipe
uname output: Linux evo 3.12.13-gentoo-3.12.13-custom #3 SMP Sat Jul 12 
18:05:24 CDT 2014 i686 Intel(R) Pentium(R) 4 CPU 1.70GHz GenuineIntel GNU/Linux
Machine Type: i686-pc-linux-gnu

Bash Version: 4.2
Patch Level: 45
Release Status: release

Description:

A string is either legal or not legal as a key for an associative array.  
However, bash accepts certain keys in some contexts but not in other contexts, 
making a few strings both legal and illegal as associative array key values.  
Bash's behavior should be consistent.

For instance, consider a key containing a single-quote character, "a'b".  The 
follow script allows this key to be both defined and accessed, but not removed. 
 If it can't be removed, it should fail to be set in the first place.  (Or, 
better, since it can be set and accessed, it should be able to be unset.)

The documentation says only that "associative arrays are referenced using 
arbitrary strings."  If there are restrictions on the content of these strings, 
that should be documented.


#!/bin/bash

declare -A foo

foo[a]="one"
foo["a'b"]="two"

echo "address@hidden"

echo ${foo[a]}
echo ${foo["a'b"]}

unset foo[a]
unset foo["a'b"]



reply via email to

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