On Fri, Jul 8, 2016 at 2:09 PM, Andrew Schulman <and...@utexas.edu> wrote:

> What's the best (simplest, most efficient, or however) way to compare two
> version strings in fish?  Any better way than writing a custom function?
>
> For example, I want to test if the current running version of fish is less
> than
> 2.3.1.  I want to compare $FISH_VERSION to 2.3.1, using the version
> component
> ordering.
>
> I looked around for builtins or standard commands for this and I didn't
> find
> any.
>

The only stock script which does anything like that is help.fish and what
it does isn't really what you're looking for. Using the new "string"
builtin:

set -l fish_version (echo $FISH_VERSION | string split '.')

Then $fish_version[1] is the major number, $fish_version[2] the minor, etc.
If you need the solution to work on fish versions older than 2.3.0 (which
don't have the string builtin) you'll need to do it the hard way:

set -l fish_version
for i in 1 2 3
    set fish_version[$i] (echo 2.3.1 | cut -d . -f $i)
end




-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank
------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to