开发者

Parse another script's output

开发者 https://www.devze.com 2023-03-31 12:14 出处:网络
I\'d like to do a script which, among other stuff, grabs the output of git branch and gets the selected branch. The typical output would be:

I'd like to do a script which, among other stuff, grabs the output of git branch and gets the selected branch. The typical output would be:

master
develop
* release-1.0
...

And I would want to get:

release-1.0

I guess it could be done using开发者_StackOverflow中文版 pipes, but I have not a single clue. Could you mates help me with this? Thanks in advance!


Use the plumbing instead:

branch=$(git symbolic-ref HEAD)

git branch's output is considered porcelain and is not recommended for use in scripts.


line=$(git branch|grep '*')
echo ${line#* }
0

精彩评论

暂无评论...
验证码 换一张
取 消