Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Globbing in a function (was Re: globbing for links in pathnames)
- X-seq: zsh-users 2110
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- To: Sweth Chandramouli <sweth@xxxxxxxxxxxxxxxxxxxx>, zsh-users@xxxxxxxxxxxxxxx
- Subject: Re: Globbing in a function (was Re: globbing for links in pathnames)
- Date: Fri, 5 Feb 1999 20:27:22 -0800
On Feb 5, 6:48pm, Sweth Chandramouli wrote:
} Subject: Globbing in a function (was Re: globbing for links in pathnames)
}
} (astaroth)~/.zfunc: which binlink
} binlink () {
} BINLIST=($1(*)) eval 'for BIN in ${=BINLIST} ; do
} ln -s ${BIN} /usr/local/bin ;
} done'
} }
} (astaroth)~/.zfunc: binlink \*
} zsh: no matches found: *(*)
Remember what I said a couple of postings ago about parameter expansion?
When a parameter is replaced by its value, the string is not tokenized.
Thus BINLIST=($1(*)) is effectively the same as BINLIST=("*"(*)). If
you use the ~ flag on the parameter expansion, tokenization is done and
you'll get the glob you expect.
Also, you don't need the = in ${=BINLIST} because BINLIST is already an
array. If you ever try to binlink a file with spaces in its name, that
extra word-split will bite you.
Finally, "ln -s" isn't going to do the right thing unless you give it a
full path (or one relative to /usr/local/bin, which could be computed if
you really work at it, but a full path is easier).
So, change the function to
binlink () {
BINLIST=($~1(*)) eval 'for BIN in $BINLIST ; do
ln -s $PWD/$BIN /usr/local/bin ;
done'
}
and it should work.
However, a better way to write that particular function would be:
binlink () {
argv=($^~==*(*))
ln -s "$PWD/$^@" /usr/local/bin
}
Can you figure out what that's doing?
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Messages sorted by:
Reverse Date,
Date,
Thread,
Author