bug-bash
[Top][All Lists]
Advanced

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

bad double-quoted pattern substitution in indexed arrays


From: Diego Augusto Molina
Subject: bad double-quoted pattern substitution in indexed arrays
Date: Sun, 27 Feb 2011 05:23:27 -0300
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101226 Lightning/1.0b3pre Thunderbird/3.1.7

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: x86_64-pc-linux-gnu-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR
uname output: Linux diegom 2.6.34-gentoo-r12 #1 SMP Mon Nov 29 06:02:02
ART 2010 x86_64 Intel(R) Pentium(R) Dual CPU T2330 @ 1.60GHz
GenuineIntel GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.1
Patch Level: 7
Release Status: release

Description:
  It's difficult to explain. Better see below the particular case I had.

  I needed to assign the elements of an array to other, but with a preceding
  single quote. The following is a simplified (yet illustrative) example.

  declare -a array1=(a b c d e f) array2=()
  array2=( "${array1[@]/#/'}" )

  AFAIK (plus the man page), the syntax of pattern substitution is
  ${parameter/pattern/string}, where "string" is just that, a string. I
have also
  tried the following:

  array2=( "${array1[@]/#/"'"}" )

  But that caused a literal preceding "'", which technically is ok.
  The ugly solution I had to take was a for loop. Nothing stressing but
bothers.

  BASH shouldn't have treated specially the single quote after the slash and
  before the closing brace (I think).

Actual Results:
  Nothing actually, just the PS2 wating for a closing single quote.

Expected Results:
  'a 'b 'c 'd 'e 'f

Repeat-By:
  (Always Reproducible.)

  declare -a my_array=(a b c d e)
  echo "${my_array[@]/#/'}"

Fix:
  None really, but two workarounds:
  1) Using a for loop.
  2) Declaring a variable, assigning it a single quote and expanding it
in the
    "string" part of the substitution:
    $ q="'"
    $ echo "${my_array[@]/#/$q}"
    (Proposed by Ulrich Müller)

  This is discussed in Gentoo's bugzilla in bug #356403


-- 

Diego Augusto Molina
diegoaugustomolina@gmail.com



reply via email to

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