目的
1 版本比较
2 浮点比较
版本比较
利用 sort -V 功能
function version_gt() { test "$(echo "$@" | tr " " "n" | sort -V | head -n 1)" != "$1"; }
function version_le() { test "$(echo "$@" | tr " " "n" | sort -V | head -n 1)" == "$1"; }
function version_lt() { test "$(echo "$@" | tr " " "n" | sort -rV | head -n 1)" != "$1"; }
function version_ge() { test "$(echo "$@" | tr " " "n" | sort -rV | head -n 1)" == "$1"; }
用于浮点比较
#!/bin/bashcompare_nums()
{#############################################num1=$1op=$2num2=$3E_BADARGS=65if ! [[ $num1 =~ ^-?[0-9]+([.][0-9]+)?$ ]]