wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Linux Creating Scripts

Total questions: 28

Worksheet time: 21mins

Name
Class
Date
1.
You want to automate a daily task of backing up your important documents directory to an external USB drive. Which scripting language is commonly used for shell scripting in Linux?
a)
Python
b)
Java
c)
C++
d)
Bash
2.
You've written a script that needs to prompt the user for a filename. How can you achieve this within the script?
a)
print "Enter filename:"
b)
echo "Enter filename:"
c)
read filename
d)
ask filename
3.
Your script needs to check if a specific file exists before proceeding. Which command can help determine this?
a)
show file
b)
find file
c)
test -f file
d)
check file
4.
You accidentally made a typo in your script and it won't run. How can you quickly identify and fix errors in your script?
a)
run the script
b)
debug the script
c)
check syntax
d)
compile the script
5.
Your script performs calculations and needs to store a result as a variable. How can you assign a value to a variable within the script?
a)
result = calculation
b)
set result = calculation
c)
declare result = calculation
d)
define result = calculation
6.
A section of your script needs to be executed repeatedly until a specific condition is met. Which loop construct can achieve this?
a)
while condition
b)
for loop
c)
if statement
d)
until condition
7.
You want your script to display a custom message after completing its tasks. How can you output text to the console within the script?
a)
print message
b)
echo message
c)
write message
d)
display message
8.
Your script needs to copy multiple files from one directory to another. How can you achieve this using a loop?
a)
for each file in directory
b)
copy all files from directory
c)
loop through directory and copy files
d)
use a while loop to copy files
9.
You want to make your script executable so you can run it from the command line. What command should you use?
a)
chmod +x script.sh
b)
run script.sh
c)
source script.sh
d)
execute script.sh
10.
Your script needs to pause for a few seconds before continuing. Which command can achieve this temporary delay?
a)
wait 10
b)
sleep 10
c)
hold 10
d)
pause 10
11.
Shell scripting is the only scripting language option available for automating tasks in Linux.
a)
True
b)
False
12.
Script errors can be automatically fixed by the system without any intervention.
a)
True
b)
False
13.
Comments within a script have no impact on its functionality and are purely for decoration.
a)
True
b)
False
14.
Assigning a value to a variable within a script requires complex syntax involving semicolons and curly braces.
a)
True
b)
False
15.
The echo command is the only way to display text messages within a script.
a)
True
b)
False
16.
Shell scripts require compilation into machine code before they can be executed.
a)
True
b)
False
17.
Scripting languages like Python offer more advanced features and functionalities compared to Bash scripting for complex automation tasks.
a)
True
b)
False
18.
The sleep command can be used to pause a script's execution for a specified time, allowing for timed delays between actions.
a)
True
b)
False
19.
It's impossible to capture and display the error message encountered by a script during its execution.
a)
True
b)
False
20.
Script arguments passed from the command line are not accessible within the script itself.
a)
True
b)
False
21.
Your script needs to pass arguments from the command line when you run it. How can you access these arguments within the script?
a)
read arguments
b)
get arguments
c)
use positional arguments
d)
access command line arguments
22.
You're collaborating on a script and want to add comments to explain specific sections of code. How can you include comments within the script?
a)
// comment
b)
# comment
c)
/* comment */
d)
! comment
23.
Your script encounters an error and exits unexpectedly. How can you capture and display the error message for debugging purposes?
a)
print error
b)
echo error
c)
show error
d)
get error
24.
You want to create a simple script that greets the user by name. How can you retrieve the user's name from the system environment?
a)
get username
b)
echo username
c)
read username
d)
show username
25.
Your script performs file operations and needs to check if a specific directory exists before proceeding. Which command is suitable for this check?
a)
test -d directory
b)
find directory
c)
show directory
d)
check directory
26.
You're writing a script that automates file transfers based on certain criteria. How can you use conditional statements to control the script's execution flow?
a)
if statement
b)
while loop
c)
for loop
d)
case statement
27.
Your script needs to read the contents of a file line by line and process each line individually. How can you achieve this using a loop?
a)
for each line in file
b)
while loop through file
c)
read each line from file
d)
use a while loop to read lines
28.
You want to improve the readability and maintainability of your script. Which practice is considered good scripting etiquette?
a)
Use meaningful variable names
b)
Add comments throughout the script
c)
Follow consistent indentation
d)
All of the above