This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Get file type information about name returned from "type -p"



> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]