I'm currently using this one-liner to get the latest release version of docker-compose
.
curl --silent "https://api.github.com/repos/docker/compose/releases/latest" | grep "tag_name" | sed -E 's/.*"([^"]+)".*/\1/'
This isn't my code.
I copied & pasted it, and it worked, and I wanted to learn more.
Specifically, I am very interested in the sed
command.
Can anyone help me understand it better?
sed -E 's/.*"([^"]+)".*/\1/'
Essentially I don't understand any of the string.
I know the items individually
(.*
= any character one or more, [^"]
= accept anything that isn't "
).
But when it is written in that way I am unsure how it works out.
Output of command without the sed
command: "tag_name": "1.22.0",
Output of command with the sed
command: 1.22.0
sed
? my gnused
, does not have-E
sed
has supported-E
(a la BSD) for a while now (4.2 in 2009) even though it was initially undocumented (documented in 4.3 2017).-E
is going to make it to the POSIX standard. GNUsed
had-r
initially for that.jq -r .tag_name
.