Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to select a value from a list with jq

I have a list of strings of tags related to a docker image.
The array looks like this:

["latest", "SOME_SHA"]

I cannot figure out how to select the value from the list that is not "latest".

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried to use jq ´ select(. != "latest"´) but this returns the entire array, and not just the "SOME_SHA" value

>Solution :

To select all values not equal to a specific $value, you could use map(select(. != $value)); to select the first such value, if any, you could write:

first(.[]|select(. != $value))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading