Bash: Shell Scripting Fundamentals
Bash: Shell Scripting Fundamentals
Up to 20 questions, shuffled on every run
Welcome to the Bash Basics Quiz! This quiz covers fundamental Bash scripting concepts, syntax, and best practices. Each question is multiple-choice, and you’ll find hints to help you along the way. Good luck!
Answer key and explanations20 questions
The quiz above draws 20 questions at random from these 30, so a second attempt will not be the same run. Everything in the pool is listed here.
What is the purpose of the "shebang" line (#! /bin/bash) at the top of a script?
AnswerIt specifies the interpreter used to execute the script
How do you correctly assign the value "Alpha" to a variable named "Project"?
AnswerProject="Alpha"
What does the variable "$?" represent?
AnswerThe exit status of the most recently executed command
Which command is used to accept user input during a script?
Answerread
How do you check if a variable "VAR" is empty?
Answer[ -z "$VAR" ]
Which brackets are preferred in modern Bash for conditional tests?
Answer`[[ ]]`
How do you perform integer arithmetic to add 5 and 2?
Answer((result = 5 + 2))
What does the "export" command do?
AnswerMakes a variable available to child processes
Which loop syntax is correct for iterating through a list of files?
Answer`for file in *.txt; do ... done`
What is the difference between single quotes (' ') and double quotes (" ")?
AnswerSingle quotes are literal; double quotes allow expansion
How do you capture the output of a command into a variable?
Answer`VAR=$(command)`
What does the "break" keyword do in a loop?
AnswerExits the loop and continues the script
Which special variable contains the number of arguments passed to a script?
Answer`$#`
How do you define a function in Bash?
Answer`my_func() { ... }`
What is the "exit 1" command typically used for?
AnswerTo signal that an error occurred during execution
What does "2>&1" do in a command?
AnswerIt merges the error stream into the output stream
Which comparison operator is used for strings in [[ ]], but NOT for integers?
Answer`==`
What is a "Here Document" (EOF)?
AnswerA method for passing multi-line input to a command
How do you run a script "backup.sh" in the background?
Answer`./backup.sh &`
What does "set -x" do?
AnswerTraces and displays each command before execution
Which variable represents all arguments passed to the script as individual quoted items?
Answer`$@`
What is the result of echo ${#VAR}?
AnswerIt returns the character length of the variable
How do you check if a file is a directory?
Answer`[ -d "$FILE" ]`
What is the purpose of the "alias" command?
AnswerTo create a custom shortcut for a command
Which command is used to replace text in a stream using regex?
Answersed
How do you evaluate if $A is equal to $B for integers?
Answer`[ $A -eq $B ]`
What happens if you run a command with a leading space (e.g., " command")?
AnswerThe command is excluded from the shell history
What is the result of "$(( 10 / 3 ))" in Bash?
AnswerA truncated integer value of 3
Which command is used to make a script wait for a specific number of seconds?
Answersleep
What is the purpose of "source script.sh"?
AnswerTo run the script within the current shell








