开发者

purpose of read rev in this bash oneliner

开发者 https://www.devze.com 2023-04-10 23:31 出处:网络
So, the following bash oneliner will generate similar output as git log git rev-list --reverse HEAD | while read rev; do git log -1 $rev; done

So, the following bash oneliner will generate similar output as git log

git rev-list --reverse HEAD | while read rev; do git log -1 $rev; done

What I want to know is, what is the purpose of read rev in this context? Is there another way this could be written witho开发者_运维知识库ut read rev perhapse with xargs?


Yes you can use xargs in this case:

git rev-list --reverse HEAD | xargs -L 1 -J % git log -1 %

To explain how read rev works here, the loop reads one line from its input (in this case, from the output of the git rev-list --reverse HEAD command) and stores it in the variable rev. Then, any commands within the loop can use the variable rev. As an example:

seq 1 5 | while read x; do echo "value is $x"; done

will show

value is 1
value is 2
value is 3
value is 4
value is 5
0

精彩评论

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

关注公众号