在当前shell中使用shell脚本修改LD_LIBRART_PATH,效果持久

问题描述 投票:0回答:0

我想用 bash 脚本将几个目录附加到变量

LD_LIBRARY_PATH
。但是,由于 bash 脚本在子 shell 中运行,我无法为当前 shell 修改
LD_LIBRARY_PATH

我有以下 bash 脚本:

#!/bin/bash
# try.sh
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/sandbox
echo LD_LIBRARY_PATH

执行

bash try.sh
后,输出为

/home/sandbox

效果不持久;当我再次执行命令

echo $PATH$
时,输出为空并且不包含
/home/sandbox
.

我知道在

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/sandbox
中附加行
.bashrc
将为所有 bash 会话添加它。但是,我想问一下是否可以简单地执行一个bash脚本来修改当前会话的变量。

bash shell syntax
© www.soinside.com 2019 - 2024. All rights reserved.