Since the OP already posted an answer, this answer will address both the OP's question and answer.
TL;DR
The OP used (( )) which requires passing a string to the let command. The let command must then parse by this string. Using [[ ]] can be parsed directly by Bash which should be more efficient.
A more detailed answer is given below.
Problem with the OP's Question
If DEBVERS contains a ., then the following script posted in the question would have produced a syntax error message when executed.
if [[ $DEBVERS -gt 12 ]]; then echo "Trixie" fi
I assume the OP meant to comment out these lines. In other words, I assume the OP meant to post what is shown below instead.
#if [[ $DEBVERS -gt 12 ]]; then # echo "Trixie" #fi
Ways to get the Version Number
The answer used the following.
DEBVERS=$(awk '{print $1}' /etc/debian_version) echo "DEBVERS = " $DEBVERS DEBMAJVERS=${DEBVERS%.*} echo "DEBMAJVERS = " $DEBMAJVERS
If only DEBMAJVERS is needed, then what is shown below could be used instead.
read -d . DEBMAJVERS < /etc/debian_version echo "DEBMAJVERS = " $DEBMAJVERS```
Note that if you only needed the current version as a single integer, then what is shown below could also have been used.
DEBMAJVERS=$(lsb_release -s -r) echo "DEBMAJVERS = " $DEBMAJVERS```
How to Compare Integers
In both the question and answer, the OP uses if in the following form. Here command2 is only executes if command1 returns an exit status of 0.
if command1; then command2 fi
The (( )) Method
The OP used the following. Here, command1 is (( DEBMAJVERS < 13 )).
if (( DEBMAJVERS < 13 )); then echo "not Trixie" fi
What is shown above is the same as what is shown below. In other words, Bash treats both the exact same way.
if let "DEBMAJVERS < 13"; then echo "not Trixie" fi
The string passed to let is evaluated as if written in the C language. If the variable DEBMAJVERS contains an integer, then the string will evaluate to a value of 1, when this integer is less than 13, otherwise the string will evaluate to a value of 0. The let command returns an exit value of 0 when the result of the evaluation is nonzero, otherwise a value of 1 is returned.
The [[ ]] Method
The OP used the following. Here, command1 is [[ $DEBVERS -gt 12 ]]. As I already stated, executing this command would produce a syntax error message, when DEBVERS contains a . character.
if [[ $DEBVERS -gt 12 ]]; then echo "Trixie" fi
The script below would eliminate the error message. Note that since this is an integer comparison DEBMAJVERS does not have to be preceded by a $ character.
if [[ DEBMAJVERS -gt 12 ]]; then echo "Trixie" fi
The follow arithmetic binary operators can be used with the [[ conditional command.
| Operator | Decription |
-eq | equal to |
-ne | not equal to |
-lt | less than |
-le | less than or equal to |
-gt | greater than |
-ge | greater than or equal to |
The [ ] Method
| Note |
| I have included this method even though the OP did not post trying this method. |
if [ $DEBMAJVERS -lt 13 ]; then echo "not Trixie" fi
What is shown above is the same as what is shown below. In other words, Bash treats both the exact same way.
if test $DEBMAJVERS -lt 13; then echo "not Trixie" fi
If the variable DEBMAJVERS contains an integer, then the test command returns an exit value of 0, when this integer is less than 13, otherwise an exit value of 1 is returned.
The Strings Method
The OP tried the following, which failed to work as desired when DEBVERS contained 9.13.
if [[ $DEBVERS > 12 ]]; then echo "Trixie" fi
If you wish to string comparisons to work properly, then 0 characters may need to be prepended to the strings before comparing. What is shown below would work provided the version number never exceeds 99999. Note that first . character and all characters to the right of the first . character are removed before prepending any 0 characters.
printf -v DEBMAJVERS "%05s" ${DEBVERS%%.*} echo "DEBMAJVERS = " $DEBMAJVERS if [[ $DEBMAJVERS > 00012 ]]; then echo "Trixie" fi
Issue with OP's Answer.
The OP references the article How to Evaluate Strings as Numbers in Bash. This article uses an example which is repeated below. The example uses the arithmetic expansion (i.e. $((X))) instead of simply first adding the integer attribute to the necessary variables.
user@debian:~$ sum=3+6 user@debian:~$ echo $sum 3+6 user@debian:~$ sum=$((3+6)) user@debian:~$ echo $sum 9 user@debian:~$ a=11 user@debian:~$ b=3 user@debian:~$ echo $a 11 user@debian:~$ echo $b 3 user@debian:~$ c=$a+$b user@debian:~$ echo $c 11+3 user@debian:~$ c=$(($a+$b)) user@debian:~$ echo $c 14 user@debian:~$ c=$((5)) user@debian:~$ c=5 user@debian:~$ d=10 user@debian:~$ e=$(($a+$b*$c-$d)) user@debian:~$ echo $e 16 user@debian:~$ sum=$((3+hello)) user@debian:~$ echo $sum 3
Below I have repeated the above, except this time the integer attribute is first added to the sum, c and e variables. The results show Bash can evaluate arithmetic expressions without having to employ arithmetic expansion.
user@debian:~$ declare -i sum c e user@debian:~$ sum=3+6 user@debian:~$ echo $sum 9 user@debian:~$ a=11 user@debian:~$ b=3 user@debian:~$ c=a+b user@debian:~$ echo $c 14 user@debian:~$ c=5 user@debian:~$ d=10 user@debian:~$ e=a+b*c-d user@debian:~$ echo $e 16 user@debian:~$ sum=3+hello user@debian:~$ echo $sum 3
Note that since the variable hello does not exist, a value of 0 is substituted.
DEBVERScontains a floating point value. The Unix & Linux answer Comparing floats with an if-else statement in a shell script says bash only supports integer numbers for comparison, and has some examples of usingbcfor floating point comparisons. This is a comment, and not an answer, since haven't attempted to create my own example.v=12.34.56; echo "${v%%.*}"→12. Was this your sticking point?