我使用快速创建程序在hyper-v上安装了ubuntu 18.04。
我试图设置一个环境变量,这个变量将在我每次登录时生效。
我把下面的行。
export BOOST_ROOT=$HOME/boost_1_69_0
在每个:
~/.profile
~/.bash_profile (did not exist by default)
一次一个,后面是一个登出和一个登入。
然后我打开一个新的终端,并发出。
echo $BOOST_ROOT
输出的是一行空白 我到底做错了什么?
如果我把它放在~.bashrc中,它就会生效,然而据我所知,这只针对新的bash终端,对于任何不在bash中运行的东西都不会生效,对吗?
我问这个问题是因为 gnome-terminal 有一个选项 (在右键 -> preferences 中) 可以把 shell 当作登录 shell.如果你不想弄乱它,你可以在 ~.profile 中这样做 (确保删除 ~.bash_profile)。
# if running bash
if [ -n "$BASH_VERSION" ]
then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]
then
. "$HOME/.bashrc"
fi
fi
我的Linux Mint发行版就是这么做的(而且~.bashrc并没有包含更多的内容)。