Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Message-ID: <2C08D4EECBDED41184BB00D0B747334202FB438D@exchanger.cacheflow.com> From: "Karr, David" To: "'cygwin AT cygwin DOT com'" Subject: RE: Get file type information about name returned from "type -p" Date: Wed, 9 May 2001 15:28:24 -0700 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" I don't care about the situation where "foo" and "foo.exe" are in the same directory. That's abnormal. I do care about the situation where "foo.exe" and "foostuff.exe" are in the same directory. AFAICS, the fact that your "-name" expression is "${FOUND_IN_PATH}*", it would find anything beginning with "foo", not just "foo" and "foo.exe", but also "foostuff.exe". What I need to determine is the exact file name associated with a "found in path" entry. In any case, I believe I've found a workable solution. I'm using the shell builtin "compgen", which generates a list of candidate completions, and that shows the full file name. -----Original Message----- From: Glen Coakley [mailto:gcoakley AT mqsoftware DOT com] Sent: Wednesday, May 09, 2001 2:21 PM To: 'cygwin AT cygwin DOT com' Subject: 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 -- Want to unsubscribe from this list? Check out: http://cygwin.com/ml/#unsubscribe-simple