From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2068 invoked by alias); 28 Aug 2015 21:02:26 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20481 Received: (qmail 17576 invoked from network); 28 Aug 2015 21:02:25 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Originating-IP: [80.3.228.158] X-Spam: 0 X-Authority: v=2.1 cv=Sd8KDalu c=1 sm=1 tr=0 a=P+FLVI8RzFchTbbqTxIDRw==:117 a=P+FLVI8RzFchTbbqTxIDRw==:17 a=NLZqzBF-AAAA:8 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=xINTw9KFIVasOMLwLRcA:9 a=CjuIK1q_8ugA:10 Date: Fri, 28 Aug 2015 21:56:48 +0100 From: Peter Stephenson To: Bart Schaefer Cc: Ray Andrews , zsh-users@zsh.org Subject: Re: string to array space problem in filenames Message-ID: <20150828215648.4483268b@ntlworld.com> In-Reply-To: <150828124334.ZM7129@torch.brasslantern.com> References: <20150821215037.6b010cf7@ntlworld.com> <55DFC1E6.5090400@eastlink.ca> <55E0AE60.9090706@eastlink.ca> <150828124334.ZM7129@torch.brasslantern.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.28; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 28 Aug 2015 12:43:34 -0700 Bart Schaefer wrote: > Your first problem here is trying to maintain .mydirstack all as one > line (echo -n) with spaces between the fields. You would be much > better served by writing one file name per line and then splitting > the file on newlines when reading it back. In fact, the cdr suite (chpwd_recent_filehandler) does this as essentially print -rl -- ${(qqqq)array_of_dirs} The four q's means use $' style quoting for this. The advantage here is if a string contains a newline (bad karma for a directory, but let's think in general) it gets written as $'...\n...' --- so it's always safe to read back a single line at a time and strip the quotes with ${(Q)...}. For efficiency, in fact, it reads the file into an array of lines using ${(f)"$(<$file)"} and takes the lines out of that array. pws