企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## ~/.profile, ~/.bashrc和~/.bash_profile 区别 1. ~/.profile ``` if [ -f "${HOME}/.bashrc" ]; then source "${HOME}/.bashrc" fi ``` > ~/.profile 执行 ~/.bashrc 2. ~/.bash_profile ``` if [ -f "${HOME}/.bashrc" ] ; then source "${HOME}/.bashrc" fi ``` > ~/.bash_profile 也会执行 ~/.bashrc 3. ~/.bashrc 因为 ~/.profile 和 ~/.bash_profile 都包含 bashrc ,所以常用配置可以放在 ~/.bashrc **结论** 把常用设置放置在 ~/.bashrc 即可 ## bashrc 与 profile 区别 - 交互式shell 在命令行等待你的输入,并且执行你提交的命令(如输入 ls) - 非交互式模式 脚本方式运行 - 登录shell 是需要用户名、密码登录后才能进入的shell - 非登录shell 不需要输入用户名和密码即可打开的Shell,直接命令`bash`就是打开一个新的非登录shell,在界面系统中打开终端也是非登录shell ### 交互式登录 两种方式 1. 直接通过终端输入账号密码登录 2. 使用`su - UserName`切换的用户 执行顺序 `/etc/profile --> /etc/profile.d/*.sh --> ~/.bash_profile--> ~/.bashrc--> /etc/bashrc ` ### 非交互式登录 四种方式 1. 两种方式`su UserName ` 2. 图形界面下打开的终端 3. 执行脚本(当我们执行脚本的时候.我们就已经进入到了一个子shell) 4. 任何其它的bash实例 `~/.bashrc--> /etc/bashrc--> /etc/profile.d/*.sh ` ## `/etc/profile` 与 ` /etc/profile.d` - 两个文件都是设置环境变量的文件 - 是永久性的环境变量,是全局变量 - /etc/profile.d/ 比 /etc/profile 好维护 - 只有Login shell 启动时才会运行 profile 这个脚本 profile.d 触发方式 在 `/etc/profile` 有脚本 ``` if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r $i ]; then . $i fi done unset i fi ``` ### 实例 #### 配置 LD_LIBRARY_PATH vim /etc/profile.d/ld_library.sh ``` export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/im_user/im_server/im_server/im_common ``` 启动 ``` source /etc/profile ``` ### /etc/profile 在新窗口失效 可能在 ubuntu 中打开新创建发现配置还是失效 ``` > vim ~/.bashrc #添加 source /etc/profile ```