From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3260 invoked from network); 7 Feb 2002 04:39:41 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 7 Feb 2002 04:39:41 -0000 Received: (qmail 24882 invoked by alias); 7 Feb 2002 04:39:34 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 16581 Received: (qmail 24854 invoked from network); 7 Feb 2002 04:39:32 -0000 Date: Wed, 6 Feb 2002 20:39:26 -0800 From: Derek Peschel To: zsh-workers@sunsite.dk Subject: BUG? - 4.0.2 - parameter substitution won't double backslashes in values Message-ID: <20020206203926.A10484@eskimo.eskimo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i I want to write the elements of $dirstack out to a file, separated by newlines. If an element in $dirstack contains a newline, I want to write a backslash before the newline in the file. Parameter substitution managed that: print ${dirstack[0]/ /\\\\ } But I also want to double any backslashes in $dirstack, and I haven't managed to do that yet with parameter substitution. The backslash sequences in the parameter seem to be interpreted before substitution happens. Suppose I have a subdirectory "a\bc" under my home directory. print $dirstack[0] /usr/home/dpeschel/ac ["\b" is a backspace] print ${dirstack[0]/\\/\\\\} /usr/home/dpeschel/ac [no change] print ${dirstack[0]/\\\\/\\\\\\\\} /usr/home/dpeschel/ac [no change] print ${dirstack[0]/b/t} /usr/home/dpeschel/a c [the "\b" gets changed to "\t" which is a tab] Then I thought of using a single backslash -- given that escape sequences happen "at a lower level" than parameter substitution, and parameter- substitution backslashes must be quoted, it makes a kind of sense that an unquoted backslash would affect the version of the value with un- processed escape sequences. The result was really weird: print ${dirstack[0]/\/t} t/usr/home/dpeschel/ac If there's another way to do this, aside from parameter substitution, that would be OK. I haven't yet tackled reading the items back from the file, but obviously writing has to work first. -- Derek