Subject: Re: Tilde is expanded in $PATH, inconsistent behavior Date: Mon, 27 Jan 2025 15:21:06 -0500
Keith Thompson <keith.s.thomp...@gmail.com> writes: > The "Tilde Expansion" section of the bash manual does talk about > using '~' when setting $PATH, but that applies only when setting > it, not when using a $PATH containing literal '~' characters. > > A user who doesn't realize that, for example, "$HOME/bin" is > expanded in double quotes but "~/bin" is not might end up with > a $PATH setting that allows direct execution of some commands > from the bash prompt, but those same commands can't be found by > other tools. The problem is a bit subtle. The core point is a fact which is diffused through Un*x systems, that "~" works only because the shell deliberately makes substitutions to make it work. In the simplest case, this command $ ~/bin/clean works *only* because the shell translates it to "/home/worley/bin/clean". The shell then hands that string to the kernel, the kernel finds the file, and executes it. On the other hand $ '~/bin/clean' bash: ~/bin/clean: No such file or directory Within that context, if an element of PATH contains a '~' character, you don't expect that to cause execution requests to look in your home directory, because '~' isn't the name of your home directory. For that matter, Bash doesn't search the path for executables; the kernel uses the PATH of the process to find the file whose execution was requested. Dale