Issue
I have a Korn shell script and the following piece of code works:
if [ $LINUXVER = 7.2 ] || [ $LINUXVER = 7.3 ]; then
But I want to modify the code to make a range that covers 7.2
, 7.3
, 7.4
, etc. I know I need to use something like [0-9]
, and I have tried a number of things, but nothing works. This script is running on multiple remote servers and not the local server where the script is located.
Any help would be appreciated.
Solution
If you are using a relatively recent ksh (ksh93 or a compatible clone) then you can use double parentheses for mathematical expressions. For instance
testver() {
if (( LINUXVER <= 7.1 || LINUXVER >= 7.4 )); then
print "Unsupported version $LINUXVER"
else
print "Supported version $LINUXVER"
fi
}
LINUXVER=6.9
testver
LINUXVER=7.2
testver
LINUXVER=8.0
testver
The output of this script is
Unsupported version 6.9
Supported version 7.2
Unsupported version 8.0
Answered By - Paul Floyd