2

in my $PATH I have folder ~/.zsh/bin which I use for small scripts and custom built executable binaries, for example I added a recently compiled tool I made called wercker_build_status to the folder. Yet when I type in the command line wercker_build_status it can't find it, I have to type the full path to the file, ~/.zsh/bin/wercker_build_status.

That's not to say nothing in the folder doesn't work, a script I have called wifi_status is in there and typing that into the command line returns the wifi status as expected.

Why is it even though it's in my $PATH I can't just use a file I add to the folder ~/.zsh/bin?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Thermatix
  • 361
  • 4
  • 15
  • I suppose it works if you open a new terminal window (or any way to spawn a new shell)? – Ulrich Schwarz Apr 03 '18 at 09:08
  • What is your PATH? Is the tool executable? Is zsh OK with having tilde in PATH instead of $HOME? – Kusalananda Apr 03 '18 at 09:09
  • @UlrichSchwarz it does not why does my $PATH matter when I explicitly stated that the folder is in the path? and yes it is executable and so far I've never had a problem with ZSH and having a tild in the PATH. – Thermatix Apr 03 '18 at 09:25
  • OK, so it's probably not a caching issue. (IIRC, zsh will cache the names for tab completion, I'm not sure if it does the same for searching the path.) – Ulrich Schwarz Apr 03 '18 at 10:18
  • M. Schwarz is thinking of https://unix.stackexchange.com/questions/408859/ , https://unix.stackexchange.com/questions/82991/ , and many others in the same vein. – JdeBP Apr 03 '18 at 17:34

1 Answers1

4

Use $HOME in your path rather than tilde (~), especially if you enclose the new PATH in double quotes. The tilde is not expanded when it occurs in quotes.

Testing:

$ mkdir "$HOME/t"

$ cat >"$HOME/t/foo" <<END
#!/bin/sh
echo "hello"
END

$ chmod +x "$HOME/t/foo"

$ PATH="$PATH:~/t"

$ foo
zsh: command not found: foo

$ PATH="$PATH:$HOME/t"

$ foo
hello

See also: Why doesn't the tilde (~) expand inside double quotes?

Kusalananda
  • 333,661