2017-02-08 225 views
0

我在Ubuntu的服务器实例的.bash_profile对谷歌的云为拉有这些功能,推动混帐分支猛砸功能

plb(){ 
        branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p') 
        git pull origin $branch 
} 
psb(){ 
        branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p') 
        git push origin $branch 
} 

如果我单独运行的代码行,则正常工作,但是当我尽量把它放在一个功能,它显示了以下错误

$ plb 
: command not found 
: command not found 

我在做什么错在这里,谢谢大家提前

输出命令: -

[email protected]:~$ proj 
[email protected]:/var/www/staging/Server/www$ branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p') 
[email protected]:/var/www/staging/Server/www$ echo $branch 
staging 
[email protected]:/var/www/staging/Server/www$ plb 
: command not found 
: command not found 
[email protected]:/var/www/staging/Server/www$ 
+0

您需要导出您的功能。尝试在你的.bash_profile中添加'export -f plb'和'export -f psb' – Aserre

+0

@Aserre添加了导出,但它仍然无法工作,现在我的.bash_profile看起来像这样 plb(){ branch = $( git branch | sed -n -e's/^ \ * \(。* \)/ \ 1/p') git pull origin $ branch } psb(){branch = $(git branch | sed - 您可以使用git push origin $ branch } export -f plb export -f psb – rohan

回答

1

您是否重新启动了会话?当您修改它时,不会自动重新读取.bash_profile。您可以通过在命令提示符下发出类似. ~/.bash_profile的命令来手动重新加载。

函数在被调用之前必须被加载到内存中,并且调用一个函数并不会自动导致定义它的文件被读取(shell无论如何都不知道哪个文件位于哪个文件中)。当函数在调用它的脚本中定义时,其定义必须在使用之前定义,出于同样的原因:shell不会在脚本文件中跳过以找到尚未定义的函数。

+0

yes我重新启动了会话,同时我也重新启动了会话,确保我在项目文件夹所在的正确目录中。 – rohan

+0

什么可能是错误的?你是否100%你的'.bash_profile'在正确的位置(你的用户主目录)并且实际上是源代码(不是作为一个单独的进程来执行)?你确定在达到你的函数定义之前它不会退出吗?你确定Bash是使用的shell,并且没有启动一个防止加载'.bash_profile'的选项吗? – Fred

+0

我有.bash_profile其他命令他们正常工作,如 '别名.. =“cd ..”' 它的唯一的功能,没有得到执行。 – rohan