TOTAL_MEM=$(free -g | grep Mem: | awk '{print $2}') JVM_MEM=50 if [ "$TOTAL_MEM" -lt "$JVM_MEM" ] then # TOTAL_MEM < JVM_MEM时,JVM_MEM为12 JVM_MEM=12 fi 参数: -lt:小于号 -gt:大于号 参考: How to get ram size in gb in bash script?How can I compare numbers in Bash?