CompTIA Server+ SK0-005 Practice Question
While hardening a portable backup script, a systems administrator needs the script to rotate logs only when the current log volume (in MB) stored in variable SIZE exceeds the configured maximum stored in MAX. The existing Bourne-shell code is:
if [ "$SIZE" > "$MAX" ]; then
/usr/local/bin/rotate_logs
fi
During testing, the shell treats the >
symbol as an output-redirection operator and the comparison fails. The script must stay POSIX-compliant and run under /bin/sh
. Which replacement will correctly perform the numeric comparison?
Escape the operator:
if [ "$SIZE" \> "$MAX" ]; then
Replace the condition with
if [ "$SIZE" -ge "$MAX" ]; then
Replace the condition with
if [ "$SIZE" -gt "$MAX" ]; then
Use arithmetic evaluation:
if (( SIZE > MAX )); then