简体   繁体   English

~/.local/bin 中的文件优先于 /usr/bin

[英]Prioritize file in ~/.local/bin over /usr/bin

I'm trying to replace the whoami command with a script that's in ~/.local/bin/ .我正在尝试用~/.local/bin/中的脚本替换whoami命令。 Is there a way to have my whoami get priority so that when I run whoami my script will run instead?有没有办法让我的 whoami 获得优先权,这样当我运行 whoami 时,我的脚本就会运行?

You'll want to put ~/.local/bin/ first in your PATH environment variable.您需要将~/.local/bin/首先放在PATH环境变量中。 Then that directory will be checked first before any other for programs to run.然后将首先检查该目录,然后再检查其他程序是否运行。

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

This is what I have in my ~/.profile file这就是我的~/.profile文件中的内容

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

and this works!这行得通!

On top of this file, it's written在这个文件的顶部,它写着

# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.

So if you have ~/.bash_profile or ~/.bash_login remove them or merge them with ~/profile .因此,如果您有~/.bash_profile~/.bash_login删除它们或将它们与~/profile合并 I don't have those files.我没有那些文件。

This is what my $PATH looks like (shortened. . .)这就是我的$PATH的样子(缩短了......)

$ echo $PATH | sed -r 's/:/\n/g'| cat -n
     1  /home/shiplu/anaconda3/condabin
     2  /home/shiplu/.sdkman/candidates/gradle/current/bin
     3  /home/shiplu/.cargo/bin
     4  /home/shiplu/.local/bin
     5  /home/shiplu/bin
     6  /usr/local/sbin
     7  /usr/local/bin
     8  /usr/sbin
     9  /usr/bin
    10  /sbin
    11  /bin
    12  /usr/games
    13  /usr/local/games
    14  /snap/bin

Check the path at line 4. It's before any other system bin directories.检查第 4 行的路径。它位于任何其他系统 bin 目录之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM