I noticed the Linux shell command 'which' does NOT show an executable file although it is alredy on the search path.
More specifically, my $PATH includes '~/.local/bin'; an executable file is ~/.local/bin/charm. 'which charm' returns nothing although I can run 'charm' with no problem. I am using Ubuntu 16.04 and bash
The issue depends on Linux distribution. If I log on to another machine of RHEL 6.10, the command 'which charm' works fine for the same executable.
The issue may also relate to nfs mount. On Ubuntu 16.04, the command 'which' seems to work fine for executables on local disks, for example, 'which which' shows '/usr/bin/which', but it does NOT find execuatables on nfs paths, which is the case for my '~/.local/bin'.
I searched online but couldn't find exaplaination. Is there a way to make the command 'which' under Ubuntu show all mached executables on path including nfs mounts?
Thanks!
Best Answer
Your
$PATH
includes~/.local/bin
where tilde hasn't been expanded.bash
will expand it on the fly each time, butwhich
(at least on Ubuntu) orsh
won't.If you want
which
to see the executables in~/.local/bin
you need to make sure tilde is expanded before thePATH
variable gets it. The string~/.local/bin
is probably added to yourPATH
by one of the startup scripts. Find the relevant line and fix it according to the examples below.Note: first run each of the following examples in a fresh shell, so you can observe (
echo "$PATH"
) how it changes the variable each time independently.This won't expand tilde character (because of quoting):
This will:
Or this:
Rules of tilde expansion are somewhat complicated. Consider using
$HOME
. Examples:To fix an already established
PATH
variable, replace~
in it with the content of$HOME
: