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.
if [ "$count" -le 10 ]; then echo many; fiIncorrect. -le tests at most 10, not at least 10.
if [ "$count" -eq 10 ]; then echo many; fiIncorrect. -eq matches only exactly 10.
if [ "$count" -ge 10 ]; then echo many; fiCorrect. -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
Shell function
A reusable group of commands that runs in the caller's shell context.
Positional parameter
A numbered argument or special value supplied to a script or function.
Control flow
Conditions, loops, and exit statuses determine which shell commands run.