Shell 脚本:if 语句评估错误

Shell script: if statements evaluated wrong

我在 shell 脚本的 for 循环内有一个简单的 if 语句

#!/bin/bash


params=(2 3)
for i in "${params[@]}"
do
    echo "$i"
    cpus=1
    if [[ $i>20 ]]; then
        echo "wrong! : $i"
        cpus=20
    else
        cpus=$i
    fi
    echo "param-in: $i"
    #do something
done

当我执行代码时,它在 i=3 时将 $i>20 计算为 TRUE。为什么会这样?

> 执行字符串比较;你想要 整数 比较。请改用 -gt