Bash: Shell Scripting Fundamentals

20 QuestionsBeginnerPublished:

Bash: Shell Scripting Fundamentals

Up to 20 questions, shuffled on every run

Quiz Configuration
Enterto start

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.

  1. 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

  2. How do you correctly assign the value "Alpha" to a variable named "Project"?

    AnswerProject="Alpha"

  3. What does the variable "$?" represent?

    AnswerThe exit status of the most recently executed command

  4. Which command is used to accept user input during a script?

    Answerread

  5. How do you check if a variable "VAR" is empty?

    Answer[ -z "$VAR" ]

  6. Which brackets are preferred in modern Bash for conditional tests?

    Answer`[[ ]]`

  7. How do you perform integer arithmetic to add 5 and 2?

    Answer((result = 5 + 2))

  8. What does the "export" command do?

    AnswerMakes a variable available to child processes

  9. Which loop syntax is correct for iterating through a list of files?

    Answer`for file in *.txt; do ... done`

  10. What is the difference between single quotes (' ') and double quotes (" ")?

    AnswerSingle quotes are literal; double quotes allow expansion

  11. How do you capture the output of a command into a variable?

    Answer`VAR=$(command)`

  12. What does the "break" keyword do in a loop?

    AnswerExits the loop and continues the script

  13. Which special variable contains the number of arguments passed to a script?

    Answer`$#`

  14. How do you define a function in Bash?

    Answer`my_func() { ... }`

  15. What is the "exit 1" command typically used for?

    AnswerTo signal that an error occurred during execution

  16. What does "2>&1" do in a command?

    AnswerIt merges the error stream into the output stream

  17. Which comparison operator is used for strings in [[ ]], but NOT for integers?

    Answer`==`

  18. What is a "Here Document" (EOF)?

    AnswerA method for passing multi-line input to a command

  19. How do you run a script "backup.sh" in the background?

    Answer`./backup.sh &`

  20. What does "set -x" do?

    AnswerTraces and displays each command before execution

  21. Which variable represents all arguments passed to the script as individual quoted items?

    Answer`$@`

  22. What is the result of echo ${#VAR}?

    AnswerIt returns the character length of the variable

  23. How do you check if a file is a directory?

    Answer`[ -d "$FILE" ]`

  24. What is the purpose of the "alias" command?

    AnswerTo create a custom shortcut for a command

  25. Which command is used to replace text in a stream using regex?

    Answersed

  26. How do you evaluate if $A is equal to $B for integers?

    Answer`[ $A -eq $B ]`

  27. What happens if you run a command with a leading space (e.g., " command")?

    AnswerThe command is excluded from the shell history

  28. What is the result of "$(( 10 / 3 ))" in Bash?

    AnswerA truncated integer value of 3

  29. Which command is used to make a script wait for a specific number of seconds?

    Answersleep

  30. What is the purpose of "source script.sh"?

    AnswerTo run the script within the current shell

Was this useful?

You might also enjoy

Check out some of our other posts on similar topics

PowerShell: Windows Scripting Fundamentals

PowerShell: Windows Scripting Fundamentals

Welcome to the PowerShell Basics Quiz! This quiz covers fundamental PowerShell concepts, cmdlets, and scripting best practices. Each question is multiple-choice, and you'll find hints to help you alon

Linux: System Administration Fundamentals

Linux: System Administration Fundamentals

Welcome to the Linux Basics Quiz! This quiz covers fundamental Linux concepts, commands, and system administration best practices. Each question is multiple-choice, and you'll find hints to help you a

Git: Version Control Fundamentals

Git: Version Control Fundamentals

Welcome to the Git Basics Quiz! This quiz covers fundamental Git concepts, version control workflows, and collaborative development best practices. Each question is multiple-choice, and you'll find hi

Ansible: Configuration Management & Automation

Ansible: Configuration Management & Automation

Welcome to the Ansible Basics Quiz! This quiz covers fundamental Ansible concepts, modules, and best practices. Each question is multiple-choice, and you'll find hints to help you along the way. Good

CI/CD: Pipeline Automation Essentials

CI/CD: Pipeline Automation Essentials

Welcome to the CI/CD Basics Quiz! This quiz covers fundamental continuous integration and continuous delivery concepts, pipeline automation, and modern DevOps best practices. Each question is multiple

Terragrunt: Infrastructure as Code Management

Terragrunt: Infrastructure as Code Management

Welcome to the Terragrunt Basics Quiz! This quiz covers fundamental Terragrunt concepts, including DRY configuration management, remote state handling, module dependencies, and best practices for mana

6 related posts