zsh-users
 help / color / mirror / code / Atom feed
From: Dan Nelson <dnelson@allantgroup.com>
To: J <jean.chalard@gmail.com>
Cc: zzapper <david@tvis.co.uk>, zsh-users@sunsite.dk
Subject: Re: Bash to Zsh Funny
Date: Wed, 9 Mar 2005 10:14:50 -0600	[thread overview]
Message-ID: <20050309161447.GI37452@dan.emsphone.com> (raw)
In-Reply-To: <fb6be96e0503090341b9bce6f@mail.gmail.com>

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


      parent reply	other threads:[~2005-03-09 16:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-09 11:26 zzapper
2005-03-09 11:41 ` J
2005-03-09 12:01   ` David Rayner
2005-03-10 13:24     ` zzapper
     [not found]       ` <david@tvis.co.uk>
2005-03-10 13:46         ` Peter Stephenson
2005-03-09 16:14   ` Dan Nelson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050309161447.GI37452@dan.emsphone.com \
    --to=dnelson@allantgroup.com \
    --cc=david@tvis.co.uk \
    --cc=jean.chalard@gmail.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).