如何在shell执行退出后添加$PATH
我想在如何在shell执行退出后添加$PATH,shell,Shell,我想在install.sh的特定目录中安装一些工具,并在test.sh中调用它们,因此我添加了如下路径: # part of install.sh path_add() { if [ -d "$1" ] && [ ":$PATH:" != *":$1:"* ]; then echo "add $1 to PATH" export PATH="$PATH:$1" echo $PATH else echo
install.sh
的特定目录中安装一些工具,并在test.sh
中调用它们,因此我添加了如下路径:
# part of install.sh
path_add()
{
if [ -d "$1" ] && [ ":$PATH:" != *":$1:"* ]; then
echo "add $1 to PATH"
export PATH="$PATH:$1"
echo $PATH
else
echo "$1 already existing in PATH"
fi
}
echo
显示$1
已添加到$PATH
,但是当install.sh
退出时,$PATH
不包含刚才添加的指定路径,如何永久添加它,并且会影响持续的shell环境
# part of install.sh
path_add()
{
if [ -d "$1" ] && [ ":$PATH:" != *":$1:"* ]; then
echo "add $1 to PATH"
#export PATH="$PATH:$1"
# global
echo "export PATH=$PATH:$1" >> /etc/profile
# or local
# echo "export PATH=$PATH:$1" >> ~/.profile
echo $PATH
else
echo "$1 already existing in PATH"
fi
}
/etc/profile-全局系统设置
~/.profile-每用户设置此帖子可能会帮助您:“