3

I've made a fresh install of Debian Wheezy, and installed zsh to it. Few days after, I've done a vanilla installation of TeX Live 2014, so I added the necessary binary paths to my $PATH. Now I started writing little scripts so I would like to put them somewhere easily accessible, that is ~/bin.

My path looks like this:

~/bin:/opt/texbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

Now, if I wanted to run something from TeX Live, it's easy:

% which pdflatex
/opt/texbin/pdflatex

No problem. But when I try running something from ~/bin, ...

% which hello_world
hello_world not found

So I double-checked:

% ls -l ~/bin
total 18
-rwxr-xr-x 1 bozbalci bozbalci 5382 Sep  8 00:28 hello_world

And it shows that hello_world is doing fine in ~/bin with its execution permissions set. I've tried rehash, but it didn't work. Help?

  • Do you have a tilde in the value of PATH, or in the command that sets PATH? You can write PATH=~/bin:/opt/texbin/… in a shell script, because the tilde is expanded. But if you run echo $PATH, it should show /home/theconjuring/bin:/opt/texbin:…. Where are you setting PATH? – Gilles Sep 7 '14 at 21:46
  • Changing ~/bin to /home/bozbalci/bin solves the issue, thanks @Gilles! – Berk Özbalcı Sep 7 '14 at 21:52
7

In a shell command like

PATH=~/bin:/opt/texbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

the tilde is expanded to your home directory when the shell command is executed. Thus the resulting value of PATH is something like /home/theconjuring/bin:/opt/texbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games.

Make sure that the tilde isn't within quotes (PATH="~/bin:…"), otherwise it stands for itself. To prepend a directory to the current value of PATH, you can use

PATH=~/bin:$PATH

In general, in shells other than zsh, $PATH outside double quotes breaks when the value contains spaces or other special characters, but in an assignment, it's safe. With export, however, you need to write export PATH=~/bin:"$PATH" (though you don't need export with PATH since it's already in the environemnt). In zsh, you don't need double quotes except when the variable may be empty, but if you set PATH in .profile, it's processed by /bin/sh or /bin/bash.

If you're setting PATH in ~/.pam_environment, however, you can't use ~ or $HOME to stand for your home directory. This file is not parsed by a shell, it's a simple list of NAME=value lines. So you need to write the paths in full.

  • 1
    With zsh, you can also prepend an element to $PATH with path[1,0]=~/bin – Stéphane Chazelas Sep 9 '14 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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