Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

If the which command is not available, is there another 'standard' method to find out where a command's executable can be found?

If there is no other 'standard' method available, the actual system I face currently is a bare Android emulator with an ash Almquist shell, if that means anything.

share|improve this question

marked as duplicate by Gilles, slm, jasonwryan, Anthon, Thomas Nyman Apr 24 at 9:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2  
    
@StephaneChazelas that may mean my question is a duplicate. I've tried to search for this question but I missed what you linked. thanks! –  naxa Apr 23 at 16:00
    
well, the other question is perhaps properly described with that all you never thought you would ever not want to know about it - this leaves some room for mine . :) –  naxa Apr 23 at 20:51

3 Answers 3

up vote 7 down vote accepted

This should be a standard solution:

type
type -t
type -p
share|improve this answer
    
you're right, it works, thank you, I forgot type. Is there a reference that declares it standard, by the way? like some document at opengroup. If there is, can you link it perhaps? –  naxa Apr 23 at 15:02
3  
type and command -V/v are standard (Unix, LSB, but optional in POSIX (XSI), type -p and type -t are not. –  Stéphane Chazelas Apr 23 at 15:11

whereis

Not quite the same, but should give you the binary's location like 'which' does.

share|improve this answer
    
good to know, thanks, but it in the current OS it does not work for me –  naxa Apr 23 at 15:03

You can search the $PATH yourself to find a command:

COMMAND=vim # This is the command  to search for
(IFS=:; for dir in $PATH; do [ -x  $dir/$COMMAND ] && echo $dir/$COMMAND; done)

(this should work in ash and many other Bourne shell derivatives)

share|improve this answer
    
this is a good option if [ is included on the target system. –  naxa Apr 23 at 20:53
    
If your shell or keyboard doesn't support "[]" (I think ash does), you can replace [ -x $dir/$COMMAND ] with test -x $dir/$COMMAND (test is a bash/ash built-in, and may also be available as a standalone executable –  Johnny Apr 23 at 21:09
    
:) it's not actually my keyboard, my ash on this Android emulator seems not to come with either [ or test. I'm not sure if I'm doing anything wrong, the system seems stock and reports ash for shell. –  naxa Apr 23 at 21:22
    
I would regard any shell without either test or [...] as unusable for any but the most limited purposes. –  iconoclast Nov 18 at 0:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.