[Top][All Lists]

[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: 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'
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

  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=( "address@hidden/#/'}" )

  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=( "address@hidden/#/"'"}" )

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

  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

  (Always Reproducible.)

  declare -a my_array=(a b c d e)
  echo "address@hidden/#/'}"

  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 "address@hidden/#/$q}"
    (Proposed by Ulrich Müller)

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


Diego Augusto Molina

reply via email to

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