Search code examples
androidzsh

Cannot find adb command even though it exists in path


Please help. Cannot find adb command even though it exists in path and it is there. It use to work but now has all of a sudden stopped working. Below is terminal output.

➜  ~ echo $PATH               
    /usr/local/opt/node@8/bin:/Applications/Postgres.app/Contents/Versions/10/bin:/Users/lance/pear/bin:/usr/local/opt/node@8/bin:/Applications/Postgres.app/Contents/Versions/10/bin:/Users/lance/pear/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:~/.composer/vendor/bin:~/Library/Android/sdk/platform-tools:~/Library/Android/sdk/emulator:~/.composer/vendor/bin:~/Library/Android/sdk/platform-tools:~/Library/Android/sdk/tools:~/Library/Android/sdk/emulator

➜  ~ cd ~/Library/Android/sdk/platform-tools

➜  platform-tools ls
NOTICE.txt        dmtracedump       fastboot          make_f2fs         package.xml       sqlite3
adb               e2fsdroid         hprof-conv        mke2fs            sload_f2fs        systrace
api               etc1tool          lib               mke2fs.conf       source.properties

➜  platform-tools ~

➜  ~ adb devices
zsh: command not found: adb

➜  ~ 

Solution

  • zsh (unlike bash) does not substitute ~ checking PATH. It also does not expand ~ within any quotes, including double quotes.

    So when adding to PATH you have to either

    • use ~ in an unquoted string
    • use the full path without ~ (with any necessary quotes),
    • use $HOME instead of ~ (within double quotes or unquoted) or

    For example:

    PATH=$PATH:~/Library/Android/sdk/platform-tools
    PATH=$PATH:/Users/lance/Library/Android/sdk/platform-tools
    PATH=$PATH:'/Users/lance/Library/Android/sdk/platform-tools'
    PATH=$PATH:$HOME/Library/Android/sdk/platform-tools
    PATH="$PATH:$HOME/Library/Android/sdk/platform-tools"