29. 在 Shell 脚本中如何比较两个数字?

在 if-then 中使用测试命令( -gt 等)来比较两个数字。例如:

  1. #!/bin/bash
  2. x=10
  3. y=20
  4. if [ $x -gt $y ]
  5. then
  6. echo x is greater than y
  7. else
  8. echo y is greater than x
  9. fi