A cloud developer is writing a shell script to automatically adjust capacity when a usage variable exceeds 80. They tried if [ $usage > 80 ] ; then action, but discovered the script always returns true, even when usage is much lower. Which approach corrects this numeric check?
Surround the threshold value with double quotes for integer checks
Declare the usage variable as a string and leave the '>' comparison
Enclose the entire condition within parentheses inside brackets
Use -gt in the condition so the script compares actual numbers
In many shell environments, using '>' compares strings rather than integers. The -gt symbol compares numeric values properly. By replacing '>' with -gt, the script evaluates the threshold correctly. Other options either rely on string comparisons or do not fix the numeric evaluation.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does '-gt' mean in shell scripting?
Open an interactive chat with Bash
Why does using '>' in shell scripting compare strings instead of numbers?