A system administrator is writing a bash script to determine if a file count, stored in a variable named FILE_COUNT, is numerically greater than 25. Which of the following conditional expressions correctly performs this check?
The correct answer uses the -gt operator inside double square brackets [[ ]] to perform a numerical comparison. The -gt operator stands for 'greater than' and is used specifically for comparing integer values. The [[ $FILE_COUNT > 25 ]] expression is incorrect because the > operator, when used inside double square brackets, performs a lexicographical (alphabetical) string comparison, not a numerical one. The [ $FILE_COUNT > 25 ] expression is incorrect because within single square brackets [ ], which is an alias for the test command, the > character is interpreted as a standard output redirection operator, not a comparison operator. This would result in an error or create an empty file named '25'. The [[ $FILE_COUNT = 25 ]] expression is incorrect because the = (or ==) operator tests for string equality, it does not check if one value is greater than another.
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 -gt operator in bash scripting?
Open an interactive chat with Bash
Why is [[ $FILE_COUNT > 25 ]] incorrect for numerical comparisons?
Open an interactive chat with Bash
What is the difference between single [ ] and double [[ ]] brackets in bash?
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