Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Ex-bash script for optimisation



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?



Messages sorted by: Reverse Date, Date, Thread, Author