When the git branch
command is executed it usually shows:
* main
.... # other branches
Having the following through command substitution and string substitution work as expected:
current_branch=$(git branch | head -n1) #1
current_branch="${current_branch/* /}" #2
echo "current_branch: '${current_branch}'"
prints only main
Question:
How to merge (if is possible) lines 1 and 2 in one?
current_branch=$(git branch | head -n1 | XXX)
What should be XXX
?
${var/pattern/replacement}
expansion doesn't take a regex, but a shell glob pattern. 2) does it matter if that's on two lines or one?