0
0
Bash Scriptingscripting~10 mins

until loop in Bash Scripting - Interactive Code Practice

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

Complete the code to create an until loop that stops when the variable count reaches 5.

Bash Scripting
count=1
until [ $count [1] 5 ]
do
  echo $count
  ((count++))
done
Drag options to blanks, or click blank then click option'
A-lt
B-gt
C-eq
D-ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using -lt instead of -gt causes the loop to never run.
Using -eq stops the loop early.
2fill in blank
medium

Complete the code to increment the variable inside the until loop.

Bash Scripting
num=0
until [ $num -eq 3 ]
do
  echo $num
  [1]
done
Drag options to blanks, or click blank then click option'
A((num++))
Bnum += 1
Cnum=num+1
Dnum++
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'num=num+1' treats num as a string, not a number.
Using 'num++' alone is not valid in bash.
3fill in blank
hard

Fix the error in the until loop condition to stop when var equals 10.

Bash Scripting
var=0
until [ $var [1] 10 ]
do
  echo $var
  ((var+=2))
done
Drag options to blanks, or click blank then click option'
A-lt
B-le
C-gt
D-ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using -lt stops the loop too early.
Using -gt causes the loop to never run.
4fill in blank
hard

Fill both blanks to create an until loop that prints numbers from 1 to 4.

Bash Scripting
i=1
until [ $i [1] 5 ]
do
  echo $i
  [2]
done
Drag options to blanks, or click blank then click option'
A-eq
B((i++))
C-lt
Di+=1
Attempts:
3 left
💡 Hint
Common Mistakes
Using -lt stops the loop immediately.
Using 'i+=1' alone is not valid syntax in bash.
5fill in blank
hard

Fill all three blanks to create an until loop that prints even numbers from 2 to 8.

Bash Scripting
num=2
until [ $num [1] 10 ]
do
  echo $num
  [2]
done
Drag options to blanks, or click blank then click option'
A-ge
B((num+=2))
C-lt
Dnum++
Attempts:
3 left
💡 Hint
Common Mistakes
Using -ge stops the loop immediately.
Using num++ increments by 1, not 2.