CompTIA Linux+ (XK0-004) — Question 275
An administrator is writing a Bash script that contains a loop that increments the value of the variable count with each loop iteration by 1. Which of the following should the administrator use?
Answer options
- A. $count++
- B. count='expr $count+1'
- C. count = $count+1
- D. ((++count))
Correct answer: A
Explanation
The correct answer is A, as '$count++' is a valid operator in Bash that increments the variable by 1. Option B is incorrect because 'expr' is unnecessary for simple arithmetic in Bash. Option C is wrong due to the spaces around the '=' operator, which is not valid in Bash. Option D is also valid for incrementing, but it is not the most straightforward syntax compared to A.