1

I have two git commands

git rev-parse --abbrev-ref HEAD
git for-each-ref --sort=-taggerdate --format '%(tag)' refs/tags/<<XX>>

I want output from first command to be used as substution for <> in second command. So far i'm writing the output of first command in a file and then using it in second.

Just wondering if there is a better way to do it.

2
  • 3
    git for-each-ref --sort=-taggerdate --format '%(tag)' refs/tags/$(git rev-parse --abbrev-ref HEAD) this is called command substitution Commented Jan 24, 2018 at 19:07
  • More verbosely, you can assign the result of a command to a variable like this var=$(git rev-parse --abbrev-ref HEAD) , so by surrounding it with $(...) and you can use the value of the variable with $var making your second command: git for-each-ref --sort=-taggerdate --format '%(tag)' refs/tags/$var Commented Jan 25, 2018 at 5:31

1 Answer 1

1

Did you try:

git for-each-ref --sort=-taggerdate --format '%(tag)' refs/tags/$(git rev-parse --abbrev-ref HEAD)

respectively

git for-each-ref --sort=-taggerdate --format '%(tag)' refs/tags/`git rev-parse --abbrev-ref HEAD`
Sign up to request clarification or add additional context in comments.

1 Comment

It is worth noting that the former notation can be used ala Matryoshka doll (command substitution inside command substitution) whereas the latter can't (or not easily).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.