delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/05/09/17:21:35

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-ID: <E1B42CFD544FD31193EE0000E87C5CE799B552@mailserver2.mqsoftware.com>
From: Glen Coakley <gcoakley AT mqsoftware DOT com>
To: "'cygwin AT cygwin DOT com'" <cygwin AT cygwin DOT com>
Subject: RE: Get file type information about name returned from "type -p"
Date: Wed, 9 May 2001 16:20:59 -0500
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)

> What is "TYPE_PATH" supposed to be?  Is that just the 
> unsuffixed name of the
> program?

Sorry, when I renamed that variable (because I thought that one might be
confusing) I missed that occurence. It should be $FOUND_IN_PATH

 
> I have a feeling that this also will not deal properly with 
> two programs
> named "foo" and "foostuff", where the files "foo", "foo.exe", 
> "foostuff",
> and "foostuff.exe" exists, and I want to verify that "foo" is before
> "foo.exe".

That depends on what you think is 'proper'. What it will do is print the
type of file that each of its arguments is. This is why I put the comment in
that you would have to determine how you want to handle that situation.
Though, by the description in your first email, I would assume you are doing
something akin to "type -p foo" in which case you would not get "foostuff".
But, you may still have "foo" and "foo.exe". Regardless, I can't solve that
one because I don't know what you would want to do if that happens.


> I also don't know why you're ending with "type -p", as AFAIK, 
> that's going
> to send it back to "program name" again, instead of "file 
> name", which is
> what I need.

That was just a typo on my part. Come on, do I have to do all of the work?
:-)
Ummm... Are you looking for the functionality that 'basename' provides?


Caveat: This snippet is for illustrative purposes only. While every attempt
has been made to ensure its correctness, it may not function as intended or
at all. It is only guaranteed to take up space.

FOUND_IN_PATH=`type -p "foo"`
if [ "$FOUND_IN_PATH != "" ]
then
    # this next line may return more than one result.
    REAL_PATH=`find -perm -+x -maxdepth 1 -name "${FOUND_IN_PATH}*"`

    # I will reiterate: DO SOMETHING INTELLIGENT HERE IF REAL_PATH CONTAINS 
    # MORE THAN ONE ITEM.
    type $REAL_PATH
fi


If I understand your problem correctly, you may want to consider:

type -a "foo" | while [ read path ]
do
    # this next line may return more than one result.
    REAL_PATH=`find -perm -+x -maxdepth 1 -name "${FOUND_IN_PATH}*"`

    # I will reiterate: DO SOMETHING INTELLIGENT HERE IF $REAL_PATH CONTAINS

    # MORE THAN ONE ITEM.
    type $REAL_PATH
done

-Glen

--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019