osx - bash: "which adb" returns nothing, but "command -v adb" returns what i'd expect -
this bash weirdness that's been bugging me.
i'm on osx.
i've installed android sdk, , result adb
tool located in folder in home directory. folder appears in path reported env
~/development/android_sdk_latest/platform-tools
.
adb
runs fine, when which adb
result empty. if command -v adb
, result full path, expected: /users/me/development/android_sdk_latest/platform-tools/adb
adb
not appear in aliases.
what subtlety of bash paths or which
in dark on?
you've run subtle incompatibility between /bin/bash
, which
command.
on system (linux mint), which
command shell script, not built-in command, , first line #! /bin/sh
. means uses /bin/sh
's handling of $path
variable.
this can vary depending on how /bin/sh
set (it's symlink /bin/bash
), little experimentation shows bash
handles literal ~
character in $path
if full path home directory, /bin/sh
not. since have
~/development/android_sdk_latest/platform-tools
as 1 of elements of $path
, bash
(your interactive shell) can find adb
command, sh
(the shell used which
) cannot.
on systems, apparently including osx system, which
binary executable. again, since it's not bash script, it's not going match bash's treatment of $path
.
i recommend making 2 changes.
first, don't put literal ~
in $path
. example, append platform-tools
directory $path
, rather this:
export path="$path:~/development/android_sdk_latest/platform-tools" # bad!
do this:
export path="$path:$home/development/android_sdk_latest/platform-tools"
the $home
expand path home directory. ~
not expanded within double-quoted strings.
second, rather using which
command, use type
command that's built bash
. type
follow rules of current shell rather of /bin/sh
, , able report shell functions , aliases which
unable see. has several useful command-line options; type help type
@ bash prompt details.
the bash shell's treatement of ~
characters in $path
documented in bash manual's section on tilde expansion.