[Top][All Lists]

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

${a[2]:=...} --> creates shell variable a[2], instead of array element.

From: William Park
Subject: ${a[2]:=...} --> creates shell variable a[2], instead of array element.
Date: Thu, 27 Feb 2003 14:08:25 -0500

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DSHELL -DHAVE_CONFIG_H  -I.  -I. -I./include -I./lib  -g 
-O4 -march=i686
uname output: Linux node1 2.4.20 #1 SMP Fri Jan 17 15:48:54 EST 2003 i686 
Machine Type: i686-pc-linux-gnu

Bash Version: 2.05b
Patch Level: 4
Release Status: release


    Using ${a[2]:=...} is okey if the array element a[2] exists.  But, if
    it doesn't exist, then shell variable a[2] is created with value '...',
    instead of creating array element a[2] and assigning '...' to it.  Of
    course, once shell variable a[2] is created, it can never be accessed
    or unset, since 'a[2]' is interpreted as array element subsequently by
    the shell.  So, ${a[2]:=...} is, in fact, write-only expression.


    The below diff-file has typo correction which I notified you earlier.

--- bash-2.05b/subst.c  Thu Feb 20 13:12:14 2003
+++ bash/subst.c        Thu Feb 27 13:47:16 2003
@@ -4115,6 +4115,11 @@
   t = temp ? savestring (temp) : savestring ("");
   t1 = dequote_string (t);
   free (t);
+#if defined (ARRAY_VARS)
+  if (valid_array_reference (name))
+      assign_array_element (name, t1);
+  else
   bind_variable (name, t1);
   free (t1);
   return (temp);
@@ -4359,7 +4364,7 @@
 #if defined (ARRAY_VARS)
     case VT_ARRAYVAR:
       a = (ARRAY *)value;
-      len = array_num_elements (a) + 1;
+      len = array_num_elements (a);

reply via email to

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