0
0
Bash Scriptingscripting~10 mins

Why loops repeat tasks efficiently in Bash Scripting - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print numbers from 1 to 5 using a loop.

Bash Scripting
for i in [1]; do echo $i; done
Drag options to blanks, or click blank then click option'
A1 2 3 4 5
Bone two three four five
Ci in 1..5
Dseq 1 10
Attempts:
3 left
💡 Hint
Common Mistakes
Using words instead of numbers in the list.
Trying to use a range syntax not supported in bash like '1..5'.
2fill in blank
medium

Complete the code to print "Hello" 3 times using a loop.

Bash Scripting
for i in [1]; do echo Hello; done
Drag options to blanks, or click blank then click option'
AHello Hello Hello
B1 2 3
Cseq 5
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single number without spaces, which is not a list.
Using the word 'Hello' instead of numbers.
3fill in blank
hard

Fix the error in the loop to print numbers 1 to 4.

Bash Scripting
for i in [1]; do echo $i; done
Drag options to blanks, or click blank then click option'
A1..4
Bseq 1 5
C1 2 3 4
Drange(1,4)
Attempts:
3 left
💡 Hint
Common Mistakes
Using Python or other language syntax like 'range(1,4)'.
Using '1..4' which is not valid in bash.
4fill in blank
hard

Fill both blanks to create a loop that prints even numbers from 2 to 10.

Bash Scripting
for num in [1]; do if [[ $num [2] 2 -eq 0 ]]; then echo $num; fi; done
Drag options to blanks, or click blank then click option'
A2 4 6 8 10
B-lt
C%
D-gt
Attempts:
3 left
💡 Hint
Common Mistakes
Using a range with odd numbers included.
Using comparison operators like '-lt' instead of modulus.
5fill in blank
hard

Fill all three blanks to create a loop that prints numbers from 1 to 5 squared.

Bash Scripting
for [1] in [2]; do echo $(( [1] [3] [1] )); done
Drag options to blanks, or click blank then click option'
Ai
B1 2 3 4 5
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '*' which adds instead of squares.
Using a list that does not contain numbers 1 to 5.