0
0
Bash Scriptingscripting~10 mins

Arithmetic expansion $(( )) 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 calculate the sum of 5 and 3 using arithmetic expansion.

Bash Scripting
result=$((5 [1] 3))
echo $result
Drag options to blanks, or click blank then click option'
A*
B-
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' will subtract instead of add.
Using '*' or '/' will multiply or divide, not add.
2fill in blank
medium

Complete the code to multiply 7 by 4 using arithmetic expansion.

Bash Scripting
result=$((7 [1] 4))
echo $result
Drag options to blanks, or click blank then click option'
A*
B-
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' or '-' will add or subtract instead of multiply.
Using '/' will divide instead of multiply.
3fill in blank
hard

Fix the error in the code to correctly subtract 2 from 10 using arithmetic expansion.

Bash Scripting
result=$((10 [1] 2))
echo $result
Drag options to blanks, or click blank then click option'
A/
B+
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' will add instead of subtract.
Using '*' or '/' will multiply or divide instead of subtract.
4fill in blank
hard

Fill both blanks to calculate (17 % 5) - 2 using arithmetic expansion.

Bash Scripting
result=$((17 [1] 5 [2] 2))
echo $result
Drag options to blanks, or click blank then click option'
A%
B+
C-
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' changes the result.
Using '*' instead of '%' does not give remainder.
5fill in blank
hard

Fill all three blanks to create a dictionary-like output with keys as numbers and values as their squares, but only for numbers greater than 3.

Bash Scripting
declare -A squares
for num in {1..5}; do
  if (( num [1] 3 )); then
    squares[[2]]=$((num [3] num))
  fi
done
for key in "${!squares[@]}"; do
  echo "$key: ${squares[$key]}"
done
Drag options to blanks, or click blank then click option'
A>
Bnum
C*
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' changes the filter condition.
Using wrong variable names causes errors.
Using '+' instead of '*' does not square the number.