* Bash to Zsh Funny
@ 2005-03-09 11:26 zzapper
2005-03-09 11:41 ` J
0 siblings, 1 reply; 6+ messages in thread
From: zzapper @ 2005-03-09 11:26 UTC (permalink / raw)
To: zsh-users
Hi,
The following runs as bash but not zsh, because the line which evaulates to:-
gvim.exe note123.txt note345.txt &
In bash fine gvim edits the two files
in zsh
gvim tries to edit the filename "note123.txt note345.txt" as tho it were one long filename
#!/bin/zsh
# gg
# description : vi all files containing $1 in name
set +x
cd c:/intranet/note/
if [ $# -gt 0 ]
then
files=$(grep -il "note [0-9][0-9][0-9].*$1" $(find . -name 'note???.txt'))
if [ "$files" != "" ]
then
files=${files//[[:space:]]/ }
echo $files
gvim.exe $files &
else
echo sorry $1 not found
fi
fi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Bash to Zsh Funny
2005-03-09 11:26 Bash to Zsh Funny zzapper
@ 2005-03-09 11:41 ` J
2005-03-09 12:01 ` David Rayner
2005-03-09 16:14 ` Dan Nelson
0 siblings, 2 replies; 6+ messages in thread
From: J @ 2005-03-09 11:41 UTC (permalink / raw)
To: zzapper; +Cc: zsh-users
> 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.
You can get more info in the FAQ,
http://zsh.sunsite.dk/FAQ/zshfaq03.html#l17
--
J
"- Watashi, DATE-tte hajimete datta no...
- Sou kai ?
- Hontou wa suki na hito to surun deshou ?" -- Tokugawa Asuka
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Bash to Zsh Funny
2005-03-09 11:41 ` J
@ 2005-03-09 12:01 ` David Rayner
2005-03-10 13:24 ` zzapper
2005-03-09 16:14 ` Dan Nelson
1 sibling, 1 reply; 6+ messages in thread
From: David Rayner @ 2005-03-09 12:01 UTC (permalink / raw)
To: J; +Cc: zsh-users
Merci
> > gvim.exe $files &
setopt shwordsplit
--
Best Regards
David Rayner MSc CEng
Frustra laborant quotquot se calculationibus fatigant pro inventione quadraturae
circuli.
http://www.rayninfo.co.uk/blogger.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Bash to Zsh Funny
2005-03-09 11:41 ` J
2005-03-09 12:01 ` David Rayner
@ 2005-03-09 16:14 ` Dan Nelson
1 sibling, 0 replies; 6+ messages in thread
From: Dan Nelson @ 2005-03-09 16:14 UTC (permalink / raw)
To: J; +Cc: zzapper, zsh-users
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-03-10 13:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-09 11:26 Bash to Zsh Funny 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
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).