nerdexam
LPI

102-500 · Question #181

What output will the following command produce? seq 1 5 20

The correct answer is B. 1 6 11 16. seq FIRST INCREMENT LAST generates a sequence starting at FIRST, stepping by INCREMENT, and stopping when the next value would exceed LAST. With seq 1 5 20, you get 1 → 6 → 11 → 16 (next would be 21, which exceeds 20), making B correct. A (1 5 10 15) is wrong because it treats…

Shells and Shell Scripting

Question

What output will the following command produce? seq 1 5 20

Options

  • A1 5 10 15
  • B1 6 11 16
  • C1 234
  • D2 345
  • E5 10 15 20

How the community answered

(49 responses)
  • A
    8% (4)
  • B
    84% (41)
  • C
    4% (2)
  • D
    2% (1)
  • E
    2% (1)

Explanation

seq FIRST INCREMENT LAST generates a sequence starting at FIRST, stepping by INCREMENT, and stopping when the next value would exceed LAST. With seq 1 5 20, you get 1 → 6 → 11 → 16 (next would be 21, which exceeds 20), making B correct.

A (1 5 10 15) is wrong because it treats 5 as the ending value and increments by 5 from a different starting logic - it confuses seq 1 5 15 or seq 5 5 20.

C and D (1 2 3 4 / 2 3 4 5) are wrong because they ignore the INCREMENT argument entirely, as if seq counted by 1s; C looks like seq 1 4, D resembles seq 2 5.

E (5 10 15 20) is wrong because it starts at 5, not 1 - it would be the output of seq 5 5 20.

Memory tip: Think of the three arguments as "From, Step, To" - seq 1 5 20 reads "from 1, step by 5, up to 20". If you ever confuse argument order, remember that the most natural reading of seq 1 5 20 is smallest-to-largest, with the middle number always being the step size.

Topics

#seq command#sequence generation#command arguments#shell basics

Community Discussion

No community discussion yet for this question.

Full 102-500 Practice