Well, the truth is that I'm not an expert at terminal variables. 😄 I just shared info to show previous threads on how to do it, but I would not be able to do it myself, sorry.
That's not a trivial thing to do. You need to create a loop searching for those values and then store the highest/lowest one into variables. Are you familiar with loops and variables?