Print many when count is at least 10.
Use POSIX test integer comparison.
Which condition is appropriate?
test's -ge operator means greater than or equal for integers. Quote the variable and separate [ and ] with spaces.
Detailed explanation
if [ "$count" >= 10 ]; then echo many; fiIncorrect. [ does not use >= as its integer comparison operator.
Incorrect. [ does not use >= as its integer comparison operator.
if [ "$count" -le 10 ]; then echo many; fiIncorrect. -le tests at most 10, not at least 10.
Incorrect. -le tests at most 10, not at least 10.
if [ "$count" -eq 10 ]; then echo many; fiIncorrect. -eq matches only exactly 10.
Incorrect. -eq matches only exactly 10.
if [ "$count" -ge 10 ]; then echo many; fiCorrect. -ge tests count greater than or equal to 10.
Correct. -ge tests count greater than or equal to 10.
Try it yourself
An example you can run in a temporary verification environment.
sh -c 'count=12; if [ "$count" -ge 10 ]; then echo many; fi'Expected result
manyKey points
- -ge means at least
- -le means at most
- -eq means equal
Notes
- Environment: POSIX sh / 状態変更なし
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.