"sh"环境不尊重PATH扩展,用户的本地PATH无效吗? [英] 'sh' environment does not respect the PATH extensions, user's local PATH not in effect?

查看:128
本文介绍了"sh"环境不尊重PATH扩展,用户的本地PATH无效吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$ bl 1
$ sh -c 'bl 1'
sh: bl: command not found

bl脚本位于用户的PATH扩展名(/home/user/.local/bin)中,但是sh环境似乎并不知道它,而bash却知道.主要的/usr/bin/sh可执行文件符号链接到/usr/bin/bash.

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.

/usr/local/bin中放置指向本地bl脚本的符号链接似乎可以解决此问题.手动扩展PATH $ PATH=/usr/bin:$HOME/.local/bin sh -c 'bl 1'也可以解决该问题,因为bash和sh都知道PATH,所以我对此并不了解.

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.

推荐答案

$ export -p |grep PATH
declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:~/.local/bin"

具有文字~是错误的.它应该已经扩展到/home/user了.当变量被分配时,外壳将扩展~,而当它们被扩展时,外壳将不扩展.

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
~

找到 shell启动脚本,其中将~/.local/bin添加到$PATH并确保~没有引用.

Find the shell startup script where ~/.local/bin is added to the $PATH and make sure ~ is not quoted.

错误:

PATH="$PATH:~/.local/bin"

右:

PATH=$PATH:~/.local/bin

这篇关于"sh"环境不尊重PATH扩展,用户的本地PATH无效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆