1

I installed sublime text 2 and created a symlink to it and placed it in ~/bin. I added ~/bin to PATH variable in ~/.zshrc.

If I try to execute subl (sublime's symlink), I get:

zsh: command not found: subl

But if I execute ~/bin/subl, it works correctly.

Echoing the PATH shows that ~/bin is in the PATH variable.:

~/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Any idea what can cause the command not found issue?

Boon
  • 40,656
  • 60
  • 209
  • 315
  • How did you set `PATH`? Adding `~/bin` should work, but echoing `$PATH` should show the tilde replaced by your actual home directory. – chepner Aug 14 '15 at 18:31
  • I added ~/bin to PATH variable directly in my .zshrc file. Echoing $PATH doesn't show the expanded version for some reason. – Boon Aug 15 '15 at 15:02

1 Answers1

9

bash interprets ~ in PATH, but most shells do not.

Use $HOME instead.

that other guy
  • 116,971
  • 11
  • 170
  • 194
  • `zsh` allows `~` as well, but apparently there was a glitch in adding `~`. – chepner Aug 14 '15 at 18:32
  • 1
    @chepner In your case you probably expanded the `~` before adding it to the PATH, e.g. with `PATH=~/bin:$PATH`. If you do `PATH="~/bin:$PATH"` or otherwise get a literal tilde into PATH, it's not interpretted. – that other guy Aug 14 '15 at 19:02
  • Right, that's what I alluded to in my comment on the question; I should have been clearer. (For full disclosure, I actually use something like `path=(~/bin $path)`, but the same principle applies.) – chepner Aug 14 '15 at 19:17