ubuntu.profile和.bashrc有问题吗

zvms9eto  于 2021-06-06  发布在  Kafka
关注(0)|答案(1)|浏览(335)

我是linux新手。我目前正在通过Kafka在线安装教程。它说要将我的kafka bin目录的路径添加到我的.profile文件中,如下所示:


# ~/.profile: executed by the command interpreter for login shells.

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

# exists.

# see /usr/share/doc/bash/examples/startup-files for examples.

# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask

# for ssh logins, install and configure the libpam-umask package.

# umask 022

# if running bash

if [ -n "$BASH_VERSION" ]; then

# include .bashrc if it exists

if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi

# set PATH so it includes user's private bin directories

DOCKER="/usr/local/bin/docker-compose"
PATH="$HOME/bin:$HOME/.local/bin:$PATH:$DOCKER"

# Ubuntu make installation of Ubuntu Make binary symlink

PATH=/home/username/.local/share/umake/bin:$PATH
cat ~/.ssh/config.d/* > ~/.ssh/config
PATH="$PATH:/home/username/softwares/kafka/kafka_2.11-1.0.0/bin"

之后,我在$path上做了一个回音,我可以看到Kafka路径添加到路径中。在帖子里,我输入了Kafka和tab,然后我可以看到Kafka相关的可选命令。
然后,教程告诉您编辑.bashrc文件。它已经在那里了。那是一个很大的文件。我在文件末尾添加了以下行(根据教程):

. ~/.profile

之后,我按照教程打开了另一个终端,看到在kafka和tab之后,我仍然得到了所有与kafka相关的选项。我在终端上看到,我没有得到我的用户名,这是一个空白的终端窗口。然后我编辑了.bashrc来删除我添加的行,然后尝试打开一个新的终端,我可以在终端上看到我的用户名。然后我关闭了所有的终端。打开一个新的,并键入Kafka和标签,我没有得到任何选项,因为早些时候。然后我打开.profile文件,我可以看到Kafka路径仍然添加。然后,我试图呼应$path,而这一次,Kafka路径不在那里。
我真搞不懂这里发生了什么。请你解释一下,让我知道如何加载。配置文件每次我打开一个终端,这就是为什么我看不到Kafka路径了,当我做了一个回声路径。

wljmcqd8

wljmcqd81#

发生了什么:
采购:
运行命令时 . somefile 您正在将该文件源代码化到您当前的shell中,这基本上意味着它将运行当前shell中的所有命令 somefile 在你现在的壳里。
某些文件在某些条件下会自动获取。
外壳类型:
交互式shell:用于输入命令和接收输出的shell。在bash中,可以通过以下方式创建交互式shell:
使用bashshell登录
从终端运行bash
登录shell:第一次登录时创建的shell。当您第一次ssh到服务器或登录到没有gui的机器时,您会收到shell。
非登录交互式shell:不是登录shell而是交互式的shell。即,在打开桌面终端应用程序时创建的shell或在运行时获得的shell bash 通过ssh登录后
~/.profile和~/.bash\u profile以及~/.bash\u登录可以通过登录shell自动获取,因此,您可能在第一次登录或手动获取(.).profile时获得了此路径
请注意,如果.bash\u配置文件存在并且可读,那么bash将不会读取.bash\u登录名或.profile。https://askubuntu.com/questions/98433/run-a-script-on-login-using-bash-login
登录shell将查找…~/。bash\u profile、~/.bash\u login和~/.profile,并从存在且可读的第一个文件读取和执行命令 man bash (信用证:cdarke)
在此之后,您可能正试图在桌面终端或辅助bash shell中打开bash,但没有获得新路径,因为只有~/.bashrc--not ~/.profile源于非登录交互式shell,并且~/.bashrc中没有此路径指令
解决方案:
添加 PATH="$PATH:/home/username/softwares/kafka/kafka_2.11-1.0.0/bin" 给你的 ~/.bashrc 而不是 ~/.profile 参考文献:
https://serverfault.com/questions/261802/what-are-the-functional-differences-between-profile-bash-profile-and-bashrc
注:
不用担心它不会出现在登录shell中,因为正如您所看到的那样.profile calls.bashrc


# if running bash

if [ -n "$BASH_VERSION" ]; then

# include .bashrc if it exists

if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi

感谢cdarke对术语和登录配置工作原理的更正

相关问题