A Linux administrator writes a script to monitor the /var partition and extracts the disk usage percentage into the variable disk. To trigger an alert when usage exceeds 90%, which operator should replace the underscore in the following snippet?
disk=$(df /var | awk 'NR==2 {print $5}' | sed 's/%//')
if [ "$disk" _ "90" ]; then
echo "Disk usage exceeds threshold: ${disk}%"
fi
The test command in bash requires a numeric comparison operator for integer values. The -gt (greater than) operator evaluates to true only when the left operand is strictly greater than the right operand. The -ge (greater than or equal) operator would also be true when usage equals 90, the > symbol inside single brackets is taken as a string comparison or file redirection, and -lt tests for values less than the threshold.
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 the -gt operator do in Bash scripting?
Open an interactive chat with Bash
Why is numeric comparison important in scripts?
Open an interactive chat with Bash
What is the difference between -gt and -ge in Bash?