
Shell Scripting using Bash (SC103) Exam
1
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