Reputation: 21
I have these functions in my .bash_profile on ubuntu server instance on google cloud for pull and push the git branch
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
}
if i run the code line individually then the work properly but when i try to put it in a function it shows the following error
$ plb
: command not found
: command not found
what am i doing wrong here, thank you in advance
Output of the command:-
rohan@staging:~$ proj
rohan@staging:/var/www/staging/Server/www$ branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
rohan@staging:/var/www/staging/Server/www$ echo $branch
staging
rohan@staging:/var/www/staging/Server/www$ plb
: command not found
: command not found
rohan@staging:/var/www/staging/Server/www$
Upvotes: 0
Views: 203
Reputation: 7015
Have you restarted your session? .bash_profile
is not re-read automatically when you modify it. You can manually reload if by issuing a command like . ~/.bash_profile
at the command prompt.
Functions must be loaded in memory before being called, and calling a function does not automatically causes the file where it is defined to be read (the shell does not know in which file any specific function is located anyway). When the function is defined inside the script from which it is called, its definition must precede its use, for the same reason : the shell will not skip ahead in the script file to find a function that has not yet been defined.
Upvotes: 1