Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a comment in a Bash script.
Bash Scripting
#[1] This is a comment
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using // or -- which are not valid comment symbols in Bash.
Forgetting to add the comment symbol at the start.
✗ Incorrect
In Bash scripts, comments start with the # symbol.
2fill in blank
mediumComplete the code to declare a variable named 'name' with value 'Alice'.
Bash Scripting
[1]=Alice Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding spaces around the equal sign.
Using keywords like var or let which are not used in Bash.
✗ Incorrect
In Bash, variables are assigned without spaces and without keywords like var or let.
3fill in blank
hardFix the error in the code to print the variable 'name' value.
Bash Scripting
echo [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the $ sign before the variable name.
Using quotes that prevent variable expansion.
✗ Incorrect
To print a variable's value in Bash, prefix it with $.
4fill in blank
hardFill both blanks to write a for loop that prints numbers 1 to 3.
Bash Scripting
for [1] in [2] do echo $[1] done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'seq 1 3' without command substitution.
Using invalid variable names.
✗ Incorrect
The loop variable is 'i' and the list is '1 2 3' to iterate over numbers 1 to 3.
5fill in blank
hardFill all three blanks to create an if statement that checks if variable 'count' is greater than 10.
Bash Scripting
if [ [1] [2] [3] ] then echo "Count is large" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of -gt inside [ ] which causes errors.
Not using $ before the variable name.
✗ Incorrect
In Bash, numeric comparison uses -gt inside [ ]. The variable is referenced with $.