100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Exam (elaborations)

Shell Scripting using Bash (SC103) Practice Exam

Rating
-
Sold
-
Pages
134
Grade
A+
Uploaded on
16-12-2024
Written in
2024/2025

The Shell Scripting using Bash (SC103) Practice Exam is designed for IT professionals specializing in shell scripting using the Bash shell. Topics include scripting fundamentals, automation, process management, and system administration tasks. Candidates are tested on their ability to write, debug, and optimize Bash scripts to automate tasks, manage system resources, and enhance operational efficiency in Unix/Linux environments.

Show more Read less
Institution
Computer Tech
Course
Computer Tech

Content preview

Shell Scripting using Bash (SC103) Exam


1. What is the purpose of the read command in Bash?

a) To write data to a file
b) To read input from the user
c) To execute a script
d) To define a variable
Answer: b) To read input from the user
Explanation: The read command is used to accept user input from the standard input
(keyboard) and assign it to a variable.

2. How can you prompt the user for input in a Bash script?

a) echo "Enter your name:"
b) read -p "Enter your name: " name
c) prompt "Enter your name:"
d) input "Enter your name:"
Answer: b) read -p "Enter your name: " name
Explanation: The -p option allows you to provide a prompt directly with the read
command.

3. Which of the following commands will store the current directory in a
variable named current_dir?

a) current_dir=$(pwd)
b) current_dir=pwd
c) current_dir=cd
d) current_dir="pwd"
Answer: a) current_dir=$(pwd)
Explanation: The $(pwd) command substitution gets the current working directory and
assigns it to the current_dir variable.

4. How do you access the first argument passed to a Bash script?

a) $1
b) $2
c) $0
d) $*
Answer: a) $1
Explanation: In Bash scripts, $1 refers to the first argument passed to the script.

5. Which command will exit a Bash script with a status of 1?

a) exit 0
b) return 1


1

, Shell Scripting using Bash (SC103) Exam


c) exit 1
d) quit 1
Answer: c) exit 1
Explanation: The exit command is used to terminate a script and return an exit status. exit
1 indicates an error or abnormal termination.

6. How can you use a variable inside a double-quoted string in Bash?

a) ${variable}
b) $(variable)
c) ^variable
d) variable[]
Answer: a) ${variable}
Explanation: Inside double quotes, variables can be used with ${variable} to ensure
correct interpretation and expansion.

7. Which of the following will list files in the current directory?

a) ls
b) dir
c) list
d) files
Answer: a) ls
Explanation: The ls command lists the files and directories in the current directory.

8. How do you make a Bash script executable?

a) chmod 755 script.sh
b) chmod +x script.sh
c) chmod 777 script.sh
d) chmod 644 script.sh

Answer: b) chmod +x script.sh
Explanation: The chmod +x command adds execute permissions to the script file.

9. What does the #!/bin/bash line at the beginning of a script do?

a) Specifies the interpreter for the script
b) Comments out the line
c) Defines a variable
d) Sets the script's execution time
Answer: a) Specifies the interpreter for the script
Explanation: The #!/bin/bash line, called a shebang, indicates that the script should be run
using the Bash interpreter.



2

, Shell Scripting using Bash (SC103) Exam


10. How can you handle errors in a Bash script?

a) By using if statements
b) By using try-catch blocks
c) By checking exit statuses
d) By ignoring errors
Answer: c) By checking exit statuses
Explanation: You can handle errors by checking the exit statuses of commands using $? to
determine if the last command was successful or not.

11. What does the && operator do in a Bash command?

a) Executes the second command only if the first command fails
b) Executes the second command only if the first command succeeds
c) Runs commands in parallel
d) Runs commands sequentially regardless of success
Answer: b) Executes the second command only if the first command succeeds
Explanation: The && operator allows you to execute the second command only if the first
command returns a success status (exit status 0).

12. How can you make a script pause for 5 seconds?

a) sleep 5
b) wait 5
c) pause 5
d) delay 5
Answer: a) sleep 5
Explanation: The sleep command pauses the execution of a script for a specified number of
seconds.

13. What does the > operator do in Bash?

a) Redirects output to a file, overwriting the file if it exists
b) Appends output to a file
c) Redirects input from a file
d) Executes a command in the background
Answer: a) Redirects output to a file, overwriting the file if it exists
Explanation: The > operator redirects the output of a command to a file, replacing the file's
contents if it already exists.

14. How can you append output to an existing file in Bash?

a) command >> file
b) command > file



3

, Shell Scripting using Bash (SC103) Exam


c) command << file
d) command 2> file
Answer: a) command >> file
Explanation: The >> operator appends the output of a command to a file without overwriting
its existing contents.

15. What is the purpose of the echo command in Bash?

a) To execute a command
b) To display a line of text
c) To create a file
d) To delete a file
Answer: b) To display a line of text
Explanation: The echo command outputs text to the terminal or to a file.

16. How do you define a variable in Bash?

a) var=value
b) var: value
c) var = value
d) var-value
Answer: a) var=value
Explanation: Variables in Bash are defined by using the syntax var=value without spaces
around the = sign.

17. How can you list all environment variables in Bash?

a) listenv
b) env
c) showenv
d) printenv
Answer: d) printenv
Explanation: The printenv command lists all environment variables and their values.

18. What does the $(command) syntax do?

a) Runs the command in the background
b) Substitutes the output of the command
c) Creates a new command
d) Executes the command on a remote server
Answer: b) Substitutes the output of the command
Explanation: The $(command) syntax is used for command substitution, where the output of
the command replaces the $(command) expression.

19. How can you access all command-line arguments passed to a script?
4

Written for

Institution
Computer Tech
Course
Computer Tech

Document information

Uploaded on
December 16, 2024
Number of pages
134
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
nikhiljain22 EXAMS
View profile
Follow You need to be logged in order to follow users or courses
Sold
950
Member since
1 year
Number of followers
33
Documents
23119
Last sold
17 hours ago

3.5

223 reviews

5
74
4
49
3
46
2
16
1
38

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions