bash - quote removal question

From: nospam55 (nospa_at_no.yahoo.no)
Date: 01/30/04


Date: Fri, 30 Jan 2004 09:01:32 +0100

Hi. I was trying to see how to detach colon-separated fields in a scalar var;
apart from the classical loops under IFS=:, the nicest ways I found are

    1. literally newline inside ${ // / } inside weak quotes:

        bash$ foo='a b:c'
        bash$ echo "${foo//:/
        }"
        a b
        c
        bash$

    2. piping to tr : $'\n'
        bash$ echo "$foo" | tr : $'\n'
        a b
        c
        bash$

Now comes the question : I wanted to say $'\n' instead of a literal newline;
 by sort of merging the former examples I tried

    3. "${foo//:/$'\n'}", i.e. :

        bash$ foo=dog:cat:monkey
        bash$ echo "${foo//:/$'\n'}"
        dog'
        'cat'
        'monkey
        bash$

the surprising result is that in the output only the outer (before dog and after
monkey) strong quotes have been removed.

Does anybody figure out why? I suppose that a relevant section in the bash manpage is :

   Quote Removal
       After the preceding expansions, all unquoted occurrences of the charac?
       ters \, ?, and " that did not result from one of the above expansions
       [i.e. essentially brace- tilde- parameter- cmd- arithmetic- pathname-
       expansion, and word splitting] are removed.

If this does matter, then maybe a useful question could be : how does bash mark
and remember which quotes did result from that expansions?

   Thank you for having read :-)