当我在 Ubuntu 12.04 中打开一个新的终端窗口时,.bashrc 中的代码不会执行。我在创建 .bash_aliases 文件时注意到了这一点。当我打开一个新终端时,别名没有出现。但是,当我输入source .bashrc别名时,它确实出现了。
每次打开新的终端窗口时都应该运行 .bashrc 对吗?
我该如何做到这一点?
Mar*_*ied 184
它不一定是运行;在标准 .bashrc 的顶部是这样的评论:
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
Run Code Online (Sandbox Code Playgroud)
I believe there is an option to run bash terminal as a login shell or not. With Ubuntu, gnome-terminal does not normally run as a login shell, so .bashrc should be run directly.
For login shells (like the virtual terminals), normally the file ~/.profile is run, unless you have either ~/.bash_profile or ~/.bash_login, but they are not there by default. By default, Ubuntu uses only .profile.
The standard ~/.profile has this in it:
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
Run Code Online (Sandbox Code Playgroud)
This runs .bashrc if it is available - assuming $BASH_VERSION is present in your environment. You can check for this by entering the command echo $BASH_VERSION, and it should display some information on version number - it should not be blank.
小智 49
就我而言,只是.bashrc缺少加载程序行.bash_profile
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
Run Code Online (Sandbox Code Playgroud)
我手动添加了它,它与我的新登录一起工作
SD.*_*SD. 11
.bash_profile保存 bash shell 的配置。当您打开终端时,它首先从~/.bash_profile. 所以你可以.bash_profile根据bashrc添加以下内容来设置shell。
. ~/.bashrc
Run Code Online (Sandbox Code Playgroud)
Nic*_*vit 10
根据评论中.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.
Run Code Online (Sandbox Code Playgroud)
就这样吧;如果~/.bash_profile或~/.bash_login存在,这些将被运行而不是~/.profile.
如果您想运行,~/.bashrc只需source ~/.bashrc在bash_profile.
小智 5
如果$BASH_VERSION未设置,请尝试使用该chsh命令将您的 shell 设置为/bin/bash.
我在 12.04 LTS 上遇到了类似的问题,结果发现新用户帐户的默认 shell 设置为/bin/sh,这就是问题的原因。
| 归档时间: |
|
| 查看次数: |
181001 次 |
| 最近记录: |