0
0
Bash Scriptingscripting~10 mins

Style guide and conventions 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 add a comment in a Bash script.

Bash Scripting
#[1] This is a comment
Drag options to blanks, or click blank then click option'
A//
B#
C!
D--
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.
2fill in blank
medium

Complete 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'
Aname
Bdeclare name
Clet name
Dvar name
Attempts:
3 left
💡 Hint
Common Mistakes
Adding spaces around the equal sign.
Using keywords like var or let which are not used in Bash.
3fill in blank
hard

Fix 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'
A$name
Bname
C"name"
D'name'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the $ sign before the variable name.
Using quotes that prevent variable expansion.
4fill in blank
hard

Fill 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'
Ai
B1 2 3
Cseq 1 3
Dnum
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'seq 1 3' without command substitution.
Using invalid variable names.
5fill in blank
hard

Fill 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'
A$count
B>
C10
D-gt
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of -gt inside [ ] which causes errors.
Not using $ before the variable name.