From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16068 invoked from network); 6 Jan 2006 00:47:37 -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; 6 Jan 2006 00:47:37 -0000 Received: (qmail 32417 invoked from network); 6 Jan 2006 00:47:28 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 6 Jan 2006 00:47:28 -0000 Received: (qmail 28901 invoked by alias); 6 Jan 2006 00:47:22 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9813 Received: (qmail 28891 invoked from network); 6 Jan 2006 00:47:21 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 6 Jan 2006 00:47:21 -0000 Received: (qmail 31467 invoked from network); 6 Jan 2006 00:47:21 -0000 Received: from anchor-post-36.mail.demon.net (194.217.242.86) by a.mx.sunsite.dk with SMTP; 6 Jan 2006 00:47:21 -0000 Received: from aberdour.demon.co.uk ([80.176.90.131] helo=VMGENERAL) by anchor-post-36.mail.demon.net with esmtp (Exim 4.42) id 1EuflH-00039D-Kq for zsh-users@sunsite.dk; Fri, 06 Jan 2006 00:47:20 +0000 From: "Tony Hasler" To: Subject: FW: Full path with ksh emulation Date: Fri, 6 Jan 2006 00:47:16 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.6353 Thread-Index: AcYR9hlBIeM230sZQkCPit/D4FXbcgAYsvQg X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Message-ID: <20060106004716.jbcSAVCLIkl8kkn9WSLi4trDiVDKv1kELfq1XzNWz0s@z> Peter, Thanks for the idea of using pushd (cd) to rationalise the path. One of those ideas that seems blindingly obvious....after someone explains it to you. Never having learnt zsh I tried your routine and there was bad news and good news. The bad news is that it didn't work. It tries to find the argument in $PATH, but when "." isn't there it reverts to the builtin. When "." is in the path you get an absolute path, but one with a "." in it. Only when the absolute path of "." is in $PATH and is the first place with an executable copy of the script does it seem to work. The good news (I think) is that I learn't enough of what you were trying to do to fix it (again I think). Do you see a flaw in the following version? Incidentally, can one put this function - and the call to emulate ksh - in the .zshrc file? Once again, thanks for your time. 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 [[ $(builtin whence $1) == .* ]]; then # Temporarilly switch to the directory of the file found. # This rationalises the directory path. pushd $1:h p=$PWD/$1:t print $PWD/$1:t popd return fi builtin whence $1 } --Tony -----Original Message----- From: Peter Stephenson [mailto:pws@csr.com] Sent: 05 January 2006 12:45 To: zsh-users@sunsite.dk Subject: Re: Full path with ksh emulation "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