0
0
Bash Scriptingscripting~20 mins

Documentation with comments in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Comment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this commented Bash script?
Consider the following Bash script with comments. What will it print when run?
Bash Scripting
#!/bin/bash
# This script prints a greeting

echo "Hello, world!"  # Print greeting
AHello, world!
B# This script prints a greeting
Cecho "Hello, world!"
DNo output
Attempts:
2 left
💡 Hint
Comments start with # and are ignored by the shell.
📝 Syntax
intermediate
1:30remaining
Which option correctly comments out a line in Bash?
In Bash scripting, how do you comment out a single line?
A// This is a comment
B<!-- This is a comment -->
C# This is a comment
D/* This is a comment */
Attempts:
2 left
💡 Hint
Bash uses a special character at the start of the line for comments.
🔧 Debug
advanced
2:30remaining
Why does this script print the comment text?
Look at this Bash script: #!/bin/bash #echo "Hello" echo "#Hello" Why does it print '#Hello' instead of nothing?
ABecause the script has a syntax error
BBecause the # inside quotes is treated as text, not a comment
CBecause the # is ignored only at the start of the line
DBecause echo always prints comments
Attempts:
2 left
💡 Hint
Think about how quotes affect comments in Bash.
🚀 Application
advanced
3:00remaining
Add comments to explain this Bash script
Here is a Bash script: #!/bin/bash for i in {1..3}; do echo "Number $i" done Which option shows the script with clear comments added?
A
#!/bin/bash
for i in {1..3}; do
  echo "Number $i"
done # Loop ends
B
#!/bin/bash
for i in {1..3}; do
  echo "Number $i" # Loop
# done
C
#!/bin/bash
for i in {1..3}; do
  echo "Number $i"
# done
D
#!/bin/bash
# Loop from 1 to 3
for i in {1..3}; do
  # Print the current number
  echo "Number $i"
done
Attempts:
2 left
💡 Hint
Good comments explain what each part does clearly.
🧠 Conceptual
expert
2:00remaining
What is the purpose of comments in Bash scripts?
Why do we add comments in Bash scripts? Choose the best answer.
ATo explain the code to humans and make it easier to understand and maintain
BTo make the script run faster by skipping commented lines
CTo prevent the script from running any commands
DTo encrypt the script content for security
Attempts:
2 left
💡 Hint
Think about who reads comments and why.