From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10994 invoked from network); 6 Dec 2006 12:28:13 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.7 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 6 Dec 2006 12:28:13 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 44563 invoked from network); 6 Dec 2006 12:28:07 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 6 Dec 2006 12:28:07 -0000 Received: (qmail 19719 invoked by alias); 6 Dec 2006 12:27:57 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 11060 Received: (qmail 19708 invoked from network); 6 Dec 2006 12:27:56 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 6 Dec 2006 12:27:56 -0000 Received: (qmail 43352 invoked from network); 6 Dec 2006 12:27:56 -0000 Received: from cluster-d.mailcontrol.com (217.69.20.190) by a.mx.sunsite.dk with SMTP; 6 Dec 2006 12:27:53 -0000 Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly37d.srv.mailcontrol.com (MailControl) with ESMTP id kB6CPNsi029585 for ; Wed, 6 Dec 2006 12:27:51 GMT Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Wed, 6 Dec 2006 12:26:55 +0000 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.8/8.13.4) with ESMTP id kB6CQnsE022278 for ; Wed, 6 Dec 2006 12:26:49 GMT Received: from csr.com (pws@localhost) by news01.csr.com (8.13.8/8.13.8/Submit) with ESMTP id kB6CQnpu022275 for ; Wed, 6 Dec 2006 12:26:49 GMT Message-Id: <200612061226.kB6CQnpu022275@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-users@sunsite.dk Subject: Re: Script breaking on cd *param In-reply-to: References: Comments: In-reply-to zzapper message dated "Wed, 06 Dec 2006 12:11:41 +0000." Date: Wed, 06 Dec 2006 12:26:49 +0000 From: Peter Stephenson X-OriginalArrivalTime: 06 Dec 2006 12:26:55.0207 (UTC) FILETIME=[D0E46770:01C71931] Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MailControl A-07-06-80 (www.mailcontrol.com) on 10.68.0.147 zzapper wrote: > Hi > The following should try to cd to a subdirectory in the 4 following ways. > > cd param > cd param* > cd *param > cd *param* > > However if it fails on the second the script breaks > with "no matches found: *param " You are likely to get some sort of error, possibly from cd, possibly highly unexpected (try it if param* expands to two files, or not a directory, for example) unless you actually test the expansion is a single directory. So you really need to be more careful. local str local -a dirs for str in param param\* \*param \*param\*; do # Expands to all matching directories, else nothing. dirs=(${~str}(N/)) if (( ${#dirs} == 1 )); then cd $dirs break fi done -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php