我想在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环境?
答案 0 :(得分:0)
# 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 - 按用户设置