0
0
Bash Scriptingscripting~10 mins

Integer variables 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 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'
Anum
Bnumber
Cint
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name different from 'num'.
Forgetting to declare the variable as integer.
2fill in blank
medium

Complete 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'
Acount
B$count
C"count"
D'count'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name without $.
Using quotes around the variable name.
3fill in blank
hard

Fix 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'
A'score'
B$score
C"score"
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Using $score inside arithmetic expression.
Using quotes around the variable name.
4fill in blank
hard

Fill 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'
Atotal
Ba
Cb
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable name for declaration.
Using the same variable twice instead of both a and b.
5fill in blank
hard

Fill 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'
Ai
B1 2 3 4 5
C$i
Dseq 1 5
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.