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.
3 Answers 3
This should be a standard solution:
type
type -t
type -p
-
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?n611x007– n611x0072014年04月23日 15:02:58 +00:00Commented Apr 23, 2014 at 15:02 -
8
type
andcommand -V/v
are standard (Unix, LSB, but optional in POSIX (XSI),type -p
andtype -t
are not.Stéphane Chazelas– Stéphane Chazelas2014年04月23日 15:11:01 +00:00Commented Apr 23, 2014 at 15:11
whereis
Not quite the same, but should give you the binary's location like 'which' does.
-
good to know, thanks, but it in the current OS it does not work for men611x007– n611x0072014年04月23日 15:03:44 +00:00Commented Apr 23, 2014 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)
-
this is a good option if
[
is included on the target system.n611x007– n611x0072014年04月23日 20:53:13 +00:00Commented Apr 23, 2014 at 20:53 -
If your shell or keyboard doesn't support "[]" (I think ash does), you can replace
[ -x $dir/$COMMAND ]
withtest -x $dir/$COMMAND
(test is a bash/ash built-in, and may also be available as a standalone executableJohnny– Johnny2014年04月23日 21:09:02 +00:00Commented Apr 23, 2014 at 21:09 -
:) it's not actually my keyboard, my
ash
on this Android emulator seems not to come with either[
ortest
. I'm not sure if I'm doing anything wrong, the system seems stock and reportsash
for shell.n611x007– n611x0072014年04月23日 21:22:09 +00:00Commented Apr 23, 2014 at 21:22 -
1I would regard any shell without either
test
or[
...]
as unusable for any but the most limited purposes.iconoclast– iconoclast2014年11月18日 00:04:17 +00:00Commented Nov 18, 2014 at 0:04
all you never thought you would ever not want to know about it
- this leaves some room for mine . :)