0
0
Bash Scriptingscripting~10 mins

[[ ]] extended test 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 test if the variable 'var' is equal to 'hello'.

Bash Scripting
if [[ $var [1] "hello" ]]; then
  echo "Match"
fi
Drag options to blanks, or click blank then click option'
A==
B=
C-eq
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' inside [[ ]] instead of '=='.
Using '-eq' which is for numbers, not strings.
2fill in blank
medium

Complete the code to check if the file 'myfile.txt' exists.

Bash Scripting
if [[ [1] "myfile.txt" ]]; then
  echo "File exists"
fi
Drag options to blanks, or click blank then click option'
A-e
B-f
C-d
D-s
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-d' which checks for directories only.
Using '-f' which checks for regular files but may fail if file is special.
3fill in blank
hard

Fix the error in the code to check if variable 'num' is greater than 10.

Bash Scripting
if [[ $num [1] 10 ]]; then
  echo "Greater"
fi
Drag options to blanks, or click blank then click option'
A>
B<
C-gt
D-eq
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' which compares strings lexicographically.
Using '-eq' which checks equality, not greater than.
4fill in blank
hard

Fill in the blank to check if variable 'word' length is greater than 3.

Bash Scripting
if [[ ${#word} [1] 3 ]]; then
  echo "Long word"
fi
Drag options to blanks, or click blank then click option'
A==
B-lt
C-eq
D-gt
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which compares strings, not numbers.
Using '-lt' which means less than, not greater.
5fill in blank
hard

Fill both blanks to check if variable 'input' is not empty and equals 'yes'.

Bash Scripting
if [[ -n $input && $input [1] [2] ]]; then
  echo "Confirmed"
fi
Drag options to blanks, or click blank then click option'
A==
B"yes"
C"no"
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' for equality.
Forgetting quotes around the string 'yes'.