zsh-users
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: Sweth Chandramouli <sweth@astaroth.nit.gwu.edu>,
	zsh-users@math.gatech.edu
Subject: Re: Globbing in a function (was Re: globbing for links in pathnames)
Date: Fri, 5 Feb 1999 20:27:22 -0800	[thread overview]
Message-ID: <990205202722.ZM26495@candle.brasslantern.com> (raw)

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


             reply	other threads:[~1999-02-06  4:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-02-06  4:27 Bart Schaefer [this message]
  -- strict thread matches above, loose matches on Subject: below --
1999-02-05 23:48 Sweth Chandramouli

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=990205202722.ZM26495@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=sweth@astaroth.nit.gwu.edu \
    --cc=zsh-users@math.gatech.edu \
    /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).