问题
$ bl 1
$ sh -c 'bl 1'
sh: bl: command not found
The bl
script is located in the user's PATH extension (/home/user/.local/bin
) but the sh
environment does not seem to be aware of it, the bash
is. The main /usr/bin/sh
executable symlinks to /usr/bin/bash
.
Placing a symlink in /usr/local/bin
pointing to the local bl
script does seem to fix the issue. Expanding the PATH manually $ PATH=/usr/bin:$HOME/.local/bin sh -c 'bl 1'
also solves it, something I don't really understand since both the bash and the sh are aware of the PATH.
$ export -p |grep PATH=
declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:~/.local/bin"
$ sh -c 'export -p |grep PATH'
export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:~/.local/bin"
"Something's missing and you have to find it" yet it's hard to look if you don't know what is missing.
回答1:
$ export -p |grep PATH declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:~/.local/bin"
Having a literal ~
is wrong. It should have been expanded to /home/user
already. The shell will expand ~
when variables are assigned but not when they're expanded.
$ foo=~ && echo $foo # expanded at assignment
/home/user
$ foo='~' && echo $foo # not expanded since the assignment is quoted
~
Find the shell startup script where ~/.local/bin
is added to the $PATH
and make sure ~
is not quoted.
Wrong:
PATH="$PATH:~/.local/bin"
Right:
PATH=$PATH:~/.local/bin
来源:https://stackoverflow.com/questions/58912836/sh-environment-does-not-respect-the-path-extensions-users-local-path-not-in