zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@sunsite.dk
Subject: Re: Ex-bash script for optimisation
Date: Sun, 13 Mar 2005 19:23:52 +0000	[thread overview]
Message-ID: <1050313192352.ZM18830@candle.brasslantern.com> (raw)
In-Reply-To: <tf29319rb8a0edm1h3r63612p9h7nbilcr@4ax.com>

On Mar 13,  6:46pm, zzapper wrote:
} Subject: Re: Ex-bash script for optimisation
}
} Only the first example worked for me, but I found $1 could be a pattern

I think you're misunderstanding what happens.

I don't know what the name of your script/function is, so I'll "vit" for
purposes of example (short for "vim text").  Suppose there is a directory
containing the files

	file.aux	file.exe	file.gif	file.txt

(1) If you give the command

	vit file*

then zsh will first expand the pattern to

	vit file.aux file.exe file.gif file.txt

and next call the function "vit" which will do (shortened for simplicity)

	filelst=( *file.aux*~*.(aux|gif|exe) )

and will eventually print "Sorry no file matched *file.aux*".  Note that
vit did nothing with file.exe file.gif file.txt, which are $2 $3 $4.

(2) If instead you tried

	vit f*t

the result is

	vit file.txt

and thus

	filelst=( *file.txt*~*.(aux|gif|exe) )

(3) If you quote the pattern

	vit 'file*'

then vit does

	filelst=( *file\**~*.(aux|gif|exe) )

and you get "Sorry no file matched *file**" which might be confusing.

What I meant about allowing $1 to be a pattern is, with ${~1} in the
filelst assignment expression you can pass the pattern quoted as in (3),
and internally to vit the pattern is expanded and you'd find file.txt
as desired.

What I meant about multiple arguments to the script is, with ${^*} in
the filelst assignment, example (1) becomes

	filelst=( *file.aux*~*.(aux|gif|exe)
		  *file.exe*~*.(aux|gif|exe)
		  *file.gif*~*.(aux|gif|exe)
		  *file.txt*~*.(aux|gif|exe) )

which again finds file.txt as desired.

I'm hoping you can extrapolate from there to what I meant by "multiple
patterns".

} and i could set a second parameter w/o problem

I'm afraid I don't understand what you mean by that.  "Set" how?  And
is anything useful done with the "second parameter"?  If so, what?  Or
is it just silently ignored?


  reply	other threads:[~2005-03-13 19:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-10 16:43 zzapper
2005-03-10 18:15 ` Peter Miller
2005-03-11  4:48   ` Bart Schaefer
2005-03-11  9:04     ` zzapper
2005-03-13 18:46     ` zzapper
2005-03-13 19:23       ` Bart Schaefer [this message]
2005-03-10 18:42 Meino Christian Cramer
2005-03-11  5:14 ` Bart Schaefer

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=1050313192352.ZM18830@candle.brasslantern.com \
    --to=schaefer@brasslantern.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).