Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start a bash 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 the wrong interpreter path like /usr/bin/python.
Forgetting the #! at the start of the line.
✗ Incorrect
The shebang line #!/bin/bash tells the system to use the bash shell to run the script.
2fill in blank
mediumComplete the command to make the script file executable.
Bash Scripting
chmod [1] myscript.sh Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using -r or -w which remove read or write permissions.
Using +r which only adds read permission, not execute.
✗ Incorrect
chmod +x adds execute permission to the script file so it can be run.
3fill in blank
hardFix the error in the script to 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
Forgetting the $ sign before PWD.
Using PWD as a command instead of a variable.
✗ Incorrect
Use $PWD to get the current directory path as an environment variable.
4fill in blank
hardFill both blanks to create a script that prints all arguments passed to it.
Bash Scripting
echo "Arguments: [1]" for arg in [2]; do echo "$arg" done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $* which treats all arguments as one string.
Quoting $@ in the loop which breaks iteration.
✗ Incorrect
Use "$@" to print all arguments as separate words and $@ to loop over each argument.
5fill in blank
hardFill all three blanks to create a script that checks if a file exists and prints a message.
Bash Scripting
if [[ [1] [2] [3] ]]; then echo "File exists." else echo "File not found." fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using -d which checks for directories, not files.
Using the wrong filename or missing quotes if needed.
✗ Incorrect
Use -f to check if a regular file exists, and specify the filename to check.