zsh-users
 help / color / mirror / code / Atom feed
* Stopping functions breaking
@ 2003-12-08 12:25 zzapper
  2003-12-08 12:52 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: zzapper @ 2003-12-08 12:25 UTC (permalink / raw)
  To: zsh-users

Hi

I'm writing a function (see below) which I call such

> pub fred

I want it to cd to any directory beginning fred, if there 0 or more
than 1 matches I wish to carry on in the script.

However whatever I try 0 or no matches breaks the script.

HELP PLEASE

function pub
{
if [ $# -gt 0 ];
then
   echo $?
   builtin chdir $1* &> /dev/null
   echo $?
zzapper
--

vim -c ":%s/^/WhfgTNabgureRIvzSUnpxre/|:%s/[R-T]/ /Ig|:normal ggVGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Stopping functions breaking
  2003-12-08 12:25 Stopping functions breaking zzapper
@ 2003-12-08 12:52 ` Peter Stephenson
  2003-12-08 13:32   ` zzapper
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2003-12-08 12:52 UTC (permalink / raw)
  To: Zsh users list

> I want it to cd to any directory beginning fred, if there 0 or more
> than 1 matches I wish to carry on in the script.
>
> However whatever I try 0 or no matches breaks the script.

Set the no_nomatch option, then the failed glob won't cause a fatal error.
The cd will fail, but won't stop later things working.

The best way to do this is probably to add

setopt localoptions nonomatch

at the top of the function.  This will ensure the options are restored
when the function exits.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Stopping functions breaking
  2003-12-08 12:52 ` Peter Stephenson
@ 2003-12-08 13:32   ` zzapper
  0 siblings, 0 replies; 3+ messages in thread
From: zzapper @ 2003-12-08 13:32 UTC (permalink / raw)
  To: zsh-users

On Mon, 08 Dec 2003 12:52:18 +0000, Peter Stephenson <pws@csr.com>
wrote:

>
>setopt localoptions nonomatch
>
Thanx, worked a treat!!

zzapper
--

vim -c ":%s/^/WhfgTNabgureRIvzSUnpxre/|:%s/[R-T]/ /Ig|:normal ggVGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-12-08 13:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-08 12:25 Stopping functions breaking zzapper
2003-12-08 12:52 ` Peter Stephenson
2003-12-08 13:32   ` zzapper

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).