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

查看:37
本文介绍了'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 了.当变量被赋值时,shell将扩展~,但当它们扩展时不会.

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天全站免登陆