I have a couple of servers on my development machine. I have a script each to run them and I am working on a few git branches at a time. So whenever I am running the script that runs the server, I want it to print which server from which branch of git I am trying to run in a different color.
Here is what I have but it is not working properly.
git_branch= git branch|grep '*'|cut -c3-
echo -e "\e[1;33;40m Running API server on git branch $git_branch \e[0m"
...
REST_OF_THE_CODE_THAT_RUNS_THE_DEV_SERVER
...
It prints the git branch first and the value does not seem to be assigned to the variable at all. I am not able to figure out where I am going wrong
To assign the result of a command line to a variable, use backquotes or
$(..)notation. For example, assuming your command line works, you could use:This notation is preferable to backquotes because it’s more easily readable, and allows nesting without the need to escape things:
Note that in your original code, your
grepshould be more specific. Remember that an asterisk really means “zero or more of the previous atom”, to grep. So this would be better: