To show the branch name of the working git repository, I have the following setting for PS1 variable.
function parse_git_branch { local branch # Direct stderr to null device in case it's not in a git repo. branch=$(git symbolic-ref HEAD 2> /dev/null); # Zero length if it's not in a git repo. if [ ! -z $branch ]; then # remove the matched part of pattern. echo "(${branch#refs/heads/})"; fi } PS1="\n\w$BASH_LIGHT_GREEN \$(parse_git_branch)$BASH_WHITE\n$ "; Question: Why do I have to precede the dollar sign command with a backslash? If I remove the backslash, it doesn't show the branch name correctly.