While reviewing a Bourne-compatible shell script that monitors workload, you notice that two integer variables have already been set:
CUR=$(pgrep -c httpd) # current number of worker processes
ALLOWED=50 # upper limit defined in a config file
The script must continue (exit status 0) only when the current number of workers is strictly lower than the configured limit. Which single conditional line, placed immediately after these assignments, meets the requirement and remains portable across standard POSIX shells?
-lt is the numeric "less-than" operator understood by the POSIX test builtin ([ … ]). Using it with the two integer variables performs an arithmetic comparison and returns exit status 0 only when the left-hand operand is smaller than the right-hand operand. The line [ "$CUR" -lt "$ALLOWED" ] therefore satisfies the requirement and works in any Bourne-compatible shell.
The other choices fail in at least one respect:
[[ $CUR < $ALLOWED ]] uses <, which is a string comparison in [[ … ]]; it does not guarantee correct numeric ordering and is not supported by /bin/sh.
[ $CUR -le $ALLOWED ] allows equality, so the script would continue even when the limit is reached, which violates the "strictly lower" condition.
(( CUR > ALLOWED )) is an arithmetic test, but it checks the opposite relation (greater than) and is not POSIX-portable because the (( … )) construct is Bash/Ksh-specific.
Therefore, only the line using -lt inside single brackets reliably implements the required logic.
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 is the purpose of the '-lt' operator in shell scripting?
Open an interactive chat with Bash
Why is the '[[ $CUR < $ALLOWED ]]' line incorrect for numeric comparisons?
Open an interactive chat with Bash
What does POSIX compliance mean in shell scripting, and why is it important?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Automation, Orchestration, and Scripting
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access