[MacPorts] #60051: gildas @202002a: sort: invalid option -- V

MacPorts noreply at macports.org
Fri Feb 7 13:38:09 UTC 2020


#60051: gildas @202002a: sort: invalid option -- V
-------------------------+----------------------
  Reporter:  ryandesign  |      Owner:  bardeau
      Type:  defect      |     Status:  assigned
  Priority:  Normal      |  Milestone:
 Component:  ports       |    Version:  2.6.2
Resolution:              |   Keywords:
      Port:  gildas      |
-------------------------+----------------------

Comment (by bardeau):

 This comes from an attempt to create a shell utility which is able to
 indicate if a program version is lower than some reference version.
 namely:
 {{{
     verle() {
         # Return 0 if first argument is "lower or equal" the second
 argument
         # NB: the line return in echo below is more portable than echo -e
 "\n"
         [  "$1" = "`echo "$1
 $2" | sort -V | head -n1`" ]
     }
     verlt() {
         # Return 0 if first argument is "lower than" second argument
         [ "$1" = "$2" ] && return 1 || verle $1 $2
     }
 }}}

 used as e.g. with some plain numbers:


 {{{
 if verlt "4.8.0" "4.70"; then
 ...
 }}}

 In the past we used the syntax
 {{{
 if [ "4.8.0" "<" "4.70" ]; then
 }}}

 "<" provides lexicographical comparison, which is valid up to versions
 9.9.9. Unfortunately, zsh does not behave correctly with the later syntax.
 Note that zsh is now the default user shell under macOS. Choice has been
 made to use the functions shown on top, which make use of "sort -V" (sort
 by version number). My tests have shown a good support on a variety of OS,
 including Catalina 10.15.2, but it seems it is not as portable as I
 expected.

 Last but not least, I need a syntax compatible with bash, dash, and zsh.
 For the time being I have no good solution.

-- 
Ticket URL: <https://trac.macports.org/ticket/60051#comment:1>
MacPorts <https://www.macports.org/>
Ports system for macOS


More information about the macports-tickets mailing list