User directory in PATH in zsh: ~ Does Not Work

5

1

I'm doing this in my .zshrc

   PATH="~/scripts:$PATH"

and if I do echo $PATH it appears as the first thing in the path. Yet this directory isn't included in the executable path (nor for tab-completion). What am I doing wrong? ls ~/scripts shows the directory as expected.

Edit: This works, though... I guess ~ doesn't work in the path?

#PATH="~/scripts:$PATH"
PATH="/Users/yar/scripts:$PATH"

Dan Rosenstark

Posted 2010-05-18T18:56:26.613

Reputation: 5 718

Answers

9

Use $HOME instead.

PATH="$HOME/scripts:$PATH"

Dan Rosenstark

Posted 2010-05-18T18:56:26.613

Reputation: 5 718

3Expansion of ~ in PATH is an abhorrent bashism. The PATH-searching library functions execlp or execvp do not expand ~, so other programs that use them to find and run programs in the PATH would also fail to search ~ entries. – Chris Johnsen – 2010-05-18T21:33:29.897

3I consider ~ to be a command-line convenience. It shouldn't be used in scripts and variable values for expansion. – Paused until further notice. – 2010-05-18T23:25:29.270

@Chris Johnsen, it's amazing, the main impact on my *nix knowledge after switching shells is learning what is universal and what is not. I think zsh is cool, but I've learned quite a bit suffering through the switch (and I'm only two days in). @Dennis Williamson, I'm getting that, and it makes sense, somehow. – Dan Rosenstark – 2010-05-19T00:29:34.780