【问题标题】:Sourcing .profile from another script in ksh从 ksh 中的另一个脚本获取 .profile
【发布时间】:2014-10-17 11:45:25
【问题描述】:

我的 .profile 文件中有一个 RESLOC 变量,它会不时更改。所以我写了一个脚本,只是从用户那里获取新名称的输入。

猫 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 语句将输出作为用户给出的值。 但是当我在终端中执行脚本后回显 $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 更新。但它的来源不正确。 请帮忙。

【问题讨论】:

    标签: ksh substitution .profile


    【解决方案1】:

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

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

    . tst.sh
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-29
      • 2014-08-30
      相关资源
      最近更新 更多