2014-10-17 28 views
0

我的.profile文件中有一个RESLOC变量,该变量会随时更改。所以我写了一个脚本,只需从用户输入新名称。从ksh中的另一个脚本采购.profile

猫tst.sh

echo "Enter the Result Location name where you would like your results to go." 
read RESL 
perl -pi.bak -e "s/([\s]+)RESLOC=\/result\/([\S]+)/$1 RESLOC=\/result\/${RESL}/g" /user/.profile 
cd /user 
. /user/.profile 
echo "$RESLOC" 

最后echo语句使输出由用户给定的值。 但是,当我在终端中执行了脚本之后执行echo $ RESLOC时,它会显示旧值。

O /脚本的病人:

Enter the Result Location name where you would like your results to go. 
Release12 


/user/Release12 

当执行完成后,尝试显示RESLOC。

echo $RESLOC 
/user/Release11 

.profile文件已被Release12更新。但它没有正确的来源。 请帮忙。

回答

1

当你运行tst.sh时,会产生一个新的shell进程,当它结束时,你的环境将返回到shell的前一个实例,即运行tst.sh的那个实例。

要修改当前shell中的环境,您需要输入tst.sh;

. tst.sh 

这将在当前shell中运行tst.sh,而不是产生新的shell进程。