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?

5
  • I suppose it works if you open a new terminal window (or any way to spawn a new shell)? Commented Apr 3, 2018 at 9:08
  • What is your PATH? Is the tool executable? Is zsh OK with having tilde in PATH instead of $HOME?
    – Kusalananda
    Commented Apr 3, 2018 at 9: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
    Commented Apr 3, 2018 at 9: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.) Commented Apr 3, 2018 at 10:18
  • M. Schwarz is thinking of unix.stackexchange.com/questions/408859 , unix.stackexchange.com/questions/82991 , and many others in the same vein.
    – JdeBP
    Commented Apr 3, 2018 at 17:34

1 Answer 1

5

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?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .