我的.profile文件中有一个RESLOC变量,该变量会不时更改。所以我写了一个脚本,只需从用户那里获取新名称的输入。
cat 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语句将输出作为user给出的值。 但是当我在终端中执行脚本后回显$ RESLOC时,它会显示旧值。
脚本的O / P:
Enter the Result Location name where you would like your results to go.
Release12
/user/Release12
尝试在执行完成后显示RESLOC。
echo $RESLOC
/user/Release11
.profile文件已使用Release12进行了更新。但它没有正确采购。 请帮忙。
答案 0 :(得分:1)
当您运行tst.sh时,会生成一个新的shell进程,当它结束时,您的环境将返回到shell的前一个实例,即运行tst.sh的那个实例。
要修改当前shell中的环境,您需要获取源tst.sh;
. tst.sh
这会在你当前的shell中运行tst.sh而不会产生一个新的shell进程。