Shell Scripting Basics – Full Quiz
← Back to Quiz Home
This quiz contains 20 questions focused on Shell Scripting fundamentals.
It helps you understand variables, execution, error handling, and basic commands .
A shell script is simply a text file containing a list of commands that the shell interprets and executes in order.
Which symbol starts a comment in a shell script?
The # symbol is used for comments. Everything after # on a line is ignored by the interpreter.
What is the purpose of the Shebang (#!) line?
The shebang (e.g., #!/bin/bash) tells the operating system which program loader (interpreter) should be used to parse the rest of the file.
How do you assign a value to a variable in Bash?
In Bash, there must be no spaces around the = assignment operator.
How do you print the value of a variable named NAME?
The $ symbol is used to access the value stored in a variable.
Which command makes a script executable?
chmod +x adds the execute permission bit to the file.
$? holds the return code of the most recently executed foreground pipeline. 0 usually means success.
Which command stops the script immediately upon error?
set -e (errexit) tells the shell to exit immediately if any command exits with a non-zero status.
What is the difference between single (') and double (") quotes?
Variables inside double quotes (e.g., "Hello $NAME") are expanded. Inside single quotes, $NAME is treated as literal text.
How do you run a script named test.sh in the current directory?
You need to provide the path (relative ./ or absolute) unless the directory is in your $PATH.
Which variable holds all command-line arguments as a single string?
$* expands to a single string containing all arguments. $@ expands to separate strings for each argument.
Which variable holds the number of arguments passed to the script?
$# expands to the decimal number of positional parameters (arguments).
How do you read user input into a variable?
The read command reads a line from standard input and assigns it to the specified variable(s).
What is $0 inside a script?
$0 expands to the name of the shell or shell script.
How do you check if a file exists using if?
The -f test operator checks if the file exists and is a regular file.
Which operator checks if a directory exists?
The -d operator returns true if the file exists and is a directory.
How do you append output to a file?
The >> operator appends output to the end of a file. > overwrites the file.
What creates a readonly variable?
The readonly command ensures the variable cannot be modified or unset.
How do you debug a bash script to print every command executed?
bash -x (xtrace) prints each command with its expanded arguments before execution.
What happens if you don't provide a shebang?
Without a shebang, the script is interpreted by the current shell (e.g., bash, zsh) of the user running it.
Quiz Progress
0 / 0 questions answered
(0% )
0 correct
Quiz Complete!
0%
Reset quiz
📚 Study Guides
📬 Weekly DevOps, Cloud & Gen AI quizzes & guides