2017-02-08 223 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