Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start a shell script with the correct shebang line.
Bash Scripting
#![1] echo "Hello, world!"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong interpreter path like /usr/bin/python for a shell script.
Forgetting the #! at the start of the script.
✗ Incorrect
The shebang line #!/bin/bash tells the system to use the Bash shell to run the script.
2fill in blank
mediumComplete the code to assign a value to a variable in a shell script.
Bash Scripting
name=[1] echo "Hello, $name!"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning a value without quotes can cause errors if the value has spaces.
Using single quotes prevents variable expansion but is okay for plain strings.
✗ Incorrect
In shell scripts, variable values with spaces or special characters should be quoted using double quotes.
3fill in blank
hardFix the error in the script to correctly print the current directory.
Bash Scripting
echo "Current directory is: [1]"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Writing pwd without command substitution just prints the word 'pwd'.
Using $pwd tries to expand a variable named pwd which is usually empty.
✗ Incorrect
Using $(pwd) runs the pwd command and inserts its output into the echo statement.
4fill in blank
hardFill both blanks to create a loop that prints numbers 1 to 5.
Bash Scripting
for i in [1] do echo [2] done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1..5 does not create a list in bash.
Printing i without $ prints the letter 'i' instead of the variable value.
✗ Incorrect
The loop iterates over the list '1 2 3 4 5' and prints each value stored in $i.
5fill in blank
hardFill all three blanks to create a conditional that checks if a file exists.
Bash Scripting
if [[ -[1] [2] ]]; then echo "File [3] exists." else echo "File does not exist." fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using -f checks if it is a regular file but -e is more general.
Using different filenames in the test and echo causes confusion.
✗ Incorrect
The -e flag checks if a file exists. The filename is 'myfile.txt' used in both places.