Create a bash script that prints out "Hello World" five times.
- User
Create a bash script that prints out "Hello World" five times.
Assistant
Architectural considerations:
-
Shebang line: Use
#!/bin/bashto explicitly specify bash as the interpreter -
Loop mechanism: Several options exist:
- C-style for loop:
for ((i=0; i<5; i++)) - Brace expansion:
for i in {1..5} - While loop with counter
- seq command:
for i in $(seq 1 5)
- C-style for loop:
-
Best approach: Brace expansion
{1..5}is the most idiomatic and efficient in bash - it's built-in (no external process), clean, and readable.
-