Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an integer variable named num with value 10.
Bash Scripting
declare -i [1]=10
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name different from 'num'.
Forgetting to declare the variable as integer.
✗ Incorrect
The
declare -i command declares an integer variable. Here, num is the variable name.2fill in blank
mediumComplete the code to add 5 to the integer variable count.
Bash Scripting
count=[1]+5
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name without
$.Using quotes around the variable name.
✗ Incorrect
To use the current value of
count, prefix it with $ to get its value.3fill in blank
hardFix the error in the code to correctly increment the integer variable score by 1.
Bash Scripting
(( [1]++ )) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
$score inside arithmetic expression.Using quotes around the variable name.
✗ Incorrect
Inside arithmetic expressions, use the variable name without
$ or quotes.4fill in blank
hardFill in the blanks to declare an integer variable total and assign it the sum of a and b.
Bash Scripting
declare -i [1]=[2]+[3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable name for declaration.
Using the same variable twice instead of both
a and b.✗ Incorrect
Declare
total as integer and assign it the sum of a and b. Both a and b are variables used in the expression.5fill in blank
hardFill all three blanks to create a loop that counts from 1 to 5 and prints each number.
Bash Scripting
for [1] in [2]; do echo [3] done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name without
$ in echo.Using
seq 1 5 without command substitution.Using quotes around the list of numbers.
✗ Incorrect
Use
i as the loop variable, iterate over the list 1 2 3 4 5, and print the value of i with $i.