Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Bash to Zsh Funny
- X-seq: zsh-users 8572
- From: Dan Nelson <dnelson@xxxxxxxxxxxxxxx>
- To: J <jean.chalard@xxxxxxxxx>
- Subject: Re: Bash to Zsh Funny
- Date: Wed, 9 Mar 2005 10:14:50 -0600
- Cc: zzapper <david@xxxxxxxxxx>, zsh-users@xxxxxxxxxx
- In-reply-to: <fb6be96e0503090341b9bce6f@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <m5nt21910820l24esnv1ba14cnlb2f5go9@xxxxxxx> <fb6be96e0503090341b9bce6f@xxxxxxxxxxxxxx>
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@xxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author