From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22637 invoked by alias); 24 Oct 2011 13:32:15 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16536 Received: (qmail 3802 invoked from network); 24 Oct 2011 13:32:12 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Mon, 24 Oct 2011 14:31:04 +0100 From: Peter Stephenson To: Zsh Users Subject: Re: checking for file existence when I don't know the exact name Message-ID: <20111024143104.07ab64eb@pwslap01u.europe.root.pri> In-Reply-To: References: Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.101.11.233] X-Scanned-By: MailControl 7.6.3 (www.mailcontrol.com) on 10.71.0.138 On Mon, 24 Oct 2011 09:16:21 -0400 TJ Luoma wrote: > I want to check to see if a file exists that matches this pattern: > > OmniFocus-XXXXX.omnilicense > > where XXXXX is some set of numbers of an unknown length. > > I've been using > > ls | egrep -q "OmniFocus.*\.omnilicense" > > but it occurs to me that I might be able to use [[ -e ]] > > However, I'm not sure what the syntax is. I tried: > > if [[ -e "OmniFocus.*.omnilicense" ]] > then > > {take action here} > > fi > > but that did not work. Tests don't do globbing. They use pattern matching for other purposes (if unquoted --- i.e. if it *did* work, which it doesn't, you wouldn't want the double quotes). The standard method is along the lines of: matchingfiles() { emulate -L zsh local -a files files=(${~*}(N)) (( ${#files} )) } if matchingfiles "OmniFocus.*.omnilicense"; then ... fi in which you now do need the double quotes. -- Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog