From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18939 invoked from network); 9 Mar 2005 16:15:20 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 9 Mar 2005 16:15:20 -0000 Received: (qmail 55326 invoked from network); 9 Mar 2005 16:15:15 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 9 Mar 2005 16:15:15 -0000 Received: (qmail 16511 invoked by alias); 9 Mar 2005 16:15:04 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8572 Received: (qmail 16500 invoked from network); 9 Mar 2005 16:15:03 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 9 Mar 2005 16:15:03 -0000 Received: (qmail 53516 invoked from network); 9 Mar 2005 16:15:00 -0000 Received: from dan.emsphone.com (199.67.51.101) by a.mx.sunsite.dk with SMTP; 9 Mar 2005 16:14:55 -0000 Received: (from dan@localhost) by dan.emsphone.com (8.13.1/8.13.1) id j29GEoOw083455; Wed, 9 Mar 2005 10:14:50 -0600 (CST) (envelope-from dan) Date: Wed, 9 Mar 2005 10:14:50 -0600 From: Dan Nelson To: J Cc: zzapper , zsh-users@sunsite.dk Subject: Re: Bash to Zsh Funny Message-ID: <20050309161447.GI37452@dan.emsphone.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-OS: FreeBSD 5.3-STABLE X-message-flag: Outlook Error User-Agent: Mutt/1.5.8i X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 In the last episode (Mar 09), J said: > > gvim.exe $files & > > When you execute this line, $files is one space-separated string. > zsh expands this to only one string and doesn't perform > word-splitting, and that's what you expect most of the time. bash on > the other hand performs word-splitting. > > Compare results of: > $ a='b c' > $ for i in $a; do echo $i; done > ...in both zsh and bash. > > If you want to activate word-splitting in zsh, you can ask for it > specifically for this expansion with ${=var}, or you can setopt > shwordsplit to activate it for all expansions. I think using arrays to store filenames is more natural: files=( *.txt ) which will preserve spaces within the filenames. Note that you can also do things like files=$( grep --null -l mytext * ) files=( ${(ps:\0:)files} ) , to get a string of null-delimited filenames, then split on the null to get your array. Note that $(find . -name 'note???.txt') is redundant; just use zsh's globbing directly. If you know the resulting filenames won't contain spaces: files=($(grep -il "note [0-9][0-9][0-9].*$1" note???.txt)) -- Dan Nelson dnelson@allantgroup.com