源代码无法在shell脚本中运行

时间:2010-12-07 19:07:42

标签: shell

我在shell脚本中有以下行:

source bash_profile

它没有错误,但它也没有做任何我能看到的事情(它没有像我期望的那样重新加载我的别名)

但是,从shell脚本所在的文件夹中,如果我只是从shell运行命令,它就像我期望的那样工作。

我从不在脚本中更改目录。实际上,这是脚本:

direction="to"
destination="local"
if [ -n $1 ]
    then
    direction=$1
fi
if [ -n $2 ]
    then
    destination=$2
fi

command=$direction$destination

if [ $command = "fromlocal" -o $command = "togit" ]
    then
    cp /c/Program\ Files/Git/etc/bash_profile /d/automata/flgitscripts/bash_profile
else
    cp /d/automata/flgitscripts/bash_profile /c/Program\ Files/Git/etc/bash_profile
fi

source /c/Program\ Files/Git/etc/bash_profile

我使用该脚本管理bash_profile的更改并将其存储在git仓库中。

为什么源命令不在shell脚本中工作?

1 个答案:

答案 0 :(得分:10)

您是否也在采购脚本:source thescriptname?否则脚本将在新shell中运行,source bash_profile命令会影响该新shell(在脚本末尾退出)。

相关问题