Sequence Generation in Shell

Level 359 keystrokes

The seq command generates a sequence of numbers for iteration.

Shell code

# $(seq 1 5) expands to 1 2 3 4 5; the loop runs once per number
# In bash, {1..5} gives the same list without running seq
1for i in $(seq 1 5); do
# Prints Number: 1 up to Number: 5
2 echo "Number: $i"
3done
# Runs once, after the loop has finished
4echo "Done!"

Output

Number: 1
Number: 2
Number: 3
Number: 4
Number: 5
Done!
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Shell code and how often they appear.

  • "× 4
  • $× 2
  • ;× 1
  • :× 1
  • !× 1
  • (× 1
  • )× 1

More Shell examples at level 3

← Shell typing practice