From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1501 invoked from network); 5 Jan 2006 12:46:59 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 5 Jan 2006 12:46:59 -0000 Received: (qmail 24711 invoked from network); 5 Jan 2006 12:46:53 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 5 Jan 2006 12:46:53 -0000 Received: (qmail 27019 invoked by alias); 5 Jan 2006 12:46:46 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9809 Received: (qmail 27010 invoked from network); 5 Jan 2006 12:46:46 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 5 Jan 2006 12:46:46 -0000 Received: (qmail 23684 invoked from network); 5 Jan 2006 12:46:46 -0000 Received: from cluster-d.mailcontrol.com (HELO rly13d.srv.mailcontrol.com) (217.69.20.190) by a.mx.sunsite.dk with SMTP; 5 Jan 2006 12:46:45 -0000 Received: from exchange03.csr.com (uuk202166.uk.customer.alter.net [62.189.241.194] (may be forged)) by rly13d.srv.mailcontrol.com (MailControl) with ESMTP id k05CkdOi022689 for ; Thu, 5 Jan 2006 12:46:44 GMT Received: from news01 ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Thu, 5 Jan 2006 12:44:43 +0000 Date: Thu, 5 Jan 2006 12:44:42 +0000 From: Peter Stephenson To: zsh-users@sunsite.dk Subject: Re: Full path with ksh emulation Message-Id: <20060105124442.32927277.pws@csr.com> In-Reply-To: <200601051033.k05AXq2p005908@rly12c.srv.mailcontrol.com> References: <200601051033.k05AXq2p005908@rly12c.srv.mailcontrol.com> Organization: Cambridge Silicon Radio X-Mailer: Sylpheed version 0.9.12 (GTK+ 1.2.10; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 05 Jan 2006 12:44:43.0118 (UTC) FILETIME=[CD0870E0:01C611F5] X-Scanned-By: MailControl A-05-40-01 (www.mailcontrol.com) on 10.68.0.123 "Tony Hasler" wrote: > Accordingly, they have hit upon the idea of using zsh to emulate ksh. That > certainly solves the original problem, but introduces a new one. In ksh the > 'whence' command always gives you the absolute path of its argument. So > 'whence $0' always gives a full path even if the command was executed by > typing './myscript'. I can find no straightforward way to do this in zsh. Put the following function after the "emulate ksh". It doesn't cover all possibilities but it should do the basics. (It's annoying there's apparently no way of rationalising the path to a directory without changing into it.) whence () { # Version of whence which expands the full path to an # executable. Uses the builtin whence if the argument * is not found in the path. # N.B.: doesn't test if the argument matches an alias, builtin # or function first, unlike the builtin. local p f # Ensure pushd doesn't ignore duplicates, # and doesn't output messages emulate -L zsh setopt pushdsilent if [[ $1 != /* ]]; then for p in $path; do if [[ -x $p/$1 ]]; then f=$p/$1 # Temporarilly switch to the directory of the file found. # This rationalises the directory path. pushd $f:h print $PWD/$f:t popd return fi done fi builtin whence $1 } -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 Your mail client is unable to display the latest news from CSR. To access our news copy this link into a web browser: http://www.csr.com/email_sig.html