Interview Quizz Logo

 
  • Home
  • About Us
  • Electronics
  • Computer Science
  • Physics
  • History
  • Contact Us
  • ☰
  1. Computer Science
  2. Programming Technologies
  3. Shell Scripting Bash Interview Question with Answer

Shell Scripting Bash Questions and Answers for Viva

Frequently asked questions and answers of Shell Scripting Bash in Programming Technologies of Computer Science to enhance your skills, knowledge on the selected topic. We have compiled the best Shell Scripting Bash Interview question and answer, trivia quiz, mcq questions, viva question, quizzes to prepare. Download Shell Scripting Bash FAQs in PDF form online for academic course, jobs preparations and for certification exams .

Intervew Quizz is an online portal with frequently asked interview, viva and trivia questions and answers on various subjects, topics of kids, school, engineering students, medical aspirants, business management academics and software professionals.




Interview Question and Answer of Shell Scripting Bash


Question-1. What is shell scripting?

Answer-1: Shell scripting is writing a series of commands in a file to automate tasks in Unix/Linux.



Question-2. What is Bash?

Answer-2: Bash (Bourne Again Shell) is a command-line interpreter and a scripting language for Unix/Linux.



Question-3. How do you create a shell script?

Answer-3: Create a file with .sh extension and add commands. Make it executable using chmod +x filename.



Question-4. How do you run a shell script?

Answer-4: Use ./scriptname.sh or bash scriptname.sh.



Question-5. What is the shebang (#!) in shell scripting?

Answer-5: It specifies the interpreter for the script. Example: #!/bin/bash.



Question-6. How do you define a variable in Bash?

Answer-6: Use variable_name=value. No spaces around the = sign.



Question-7. How do you access the value of a variable?

Answer-7: Use $variable_name.



Question-8. What are positional parameters in Bash?

Answer-8: They are special variables like $1, $2, representing script arguments passed during execution.



Question-9. How do you read input from the user in Bash?

Answer-9: Use the read command. Example: read username.



Question-10. What is the use of echo in shell scripting?

Answer-10: echo prints text or variables to the terminal.



Question-11. What is the purpose of test in shell scripting?

Answer-11: test evaluates conditional expressions and returns a status.



Question-12. What is the difference between = and == in Bash?

Answer-12: = is used for assigning values, while == is used for string comparison.



Question-13. How do you write an if statement in Bash?

Answer-13: Example: if [ condition ]; then commands; fi.



Question-14. How do you write a for loop in Bash?

Answer-14: Example: for var in list; do commands; done.



Question-15. What is the while loop syntax in Bash?

Answer-15: Example: while [ condition ]; do commands; done.



Question-16. How do you comment in a Bash script?

Answer-16: Use # for single-line comments.



Question-17. What are special variables $?, $0, and $$?

Answer-17: $?: Exit status, $0: Script name, $$: Script's process ID.



Question-18. How do you use arithmetic operations in Bash?

Answer-18: Use $((expression)). Example: result=$((a + b)).



Question-19. How do you check if a file exists in Bash?

Answer-19: Use [ -e filename ].



Question-20. How do you append text to a file in Bash?

Answer-20: Use >>. Example: echo "text" >> file.txt.



Question-21. What is a function in Bash?

Answer-21: A reusable block of code defined using function name { commands; }.



Question-22. How do you call a function in Bash?

Answer-22: Use the function name followed by parentheses. Example: myFunction.



Question-23. What is the difference between > and >>?

Answer-23: > overwrites a file, while >> appends to a file.



Question-24. What is the purpose of grep?

Answer-24: grep searches for patterns in files or outputs. Example: grep "pattern" file.



Question-25. How do you use case statements in Bash?

Answer-25: Example: case variable in pattern) commands ;; esac.



Question-26. How do you check the length of a string in Bash?

Answer-26: Use ${#string}. Example: length=${#mystring}.



Question-27. How do you split a string in Bash?

Answer-27: Use IFS and read. Example: IFS=',' read -r -a array <<< "$string".



Question-28. What is the difference between & and && in Bash?

Answer-28: & runs a command in the background, while && runs the next command only if the first succeeds.



Question-29. How do you create an array in Bash?

Answer-29: Use array=(element1 element2). Access with ${array[index]}.



Question-30. How do you find the length of an array in Bash?

Answer-30: Use ${#array[@]}. Example: length=${#array[@]}.



Question-31. What is the purpose of awk in shell scripting?

Answer-31: awk is used for text processing and data extraction.



Question-32. What does sed do in shell scripting?

Answer-32: sed is a stream editor for text manipulation. Example: sed 's/old/new/g' file.



Question-33. How do you trap signals in Bash?

Answer-33: Use the trap command. Example: trap "cleanup_function" SIGINT.



Question-34. How do you check if a directory exists?

Answer-34: Use [ -d directory_name ].



Question-35. What is the use of set -e in Bash?

Answer-35: set -e exits the script immediately if a command fails.



Question-36. What is the purpose of the export command?

Answer-36: export makes a variable available to child processes.



Question-37. How do you concatenate strings in Bash?

Answer-37: Use string1$string2. Example: fullstring="$string1$string2".



Question-38. What is the difference between . and source?

Answer-38: They are identical and are used to execute a script in the current shell.



Question-39. What is the eval command in Bash?

Answer-39: eval executes a string as a command. Example: eval "ls -l".



Question-40. How do you redirect both stdout and stderr to a file?

Answer-40: Use command > file 2>&1.



Question-41. How do you create a cron job for a shell script?

Answer-41: Use crontab -e to add a job. Example: 0 5 * * * /path/to/script.sh.



Question-42. How do you check if a variable is empty?

Answer-42: Use [ -z "$variable" ].



Question-43. What is the purpose of shift in shell scripting?

Answer-43: shift moves the positional parameters left.



Question-44. How do you declare a readonly variable in Bash?

Answer-44: Use readonly or declare -r. Example: readonly VAR="value".



Question-45. What is the use of ulimit in shell scripting?

Answer-45: ulimit sets resource limits for processes.



Question-46. How do you find the exit status of a command?

Answer-46: Use $?. Example: if [ $? -eq 0 ]; then ....



Question-47. What is the difference between hard and soft links?

Answer-47: Hard links point to the same inode, while soft links are shortcuts to a file.



Question-48. How do you check the running shell?

Answer-48: Use echo $SHELL.



Question-49. What does exec do in shell scripting?

Answer-49: exec replaces the current shell process with the specified command.



Question-50. How do you debug a Bash script?

Answer-50: Use bash -x scriptname.sh or add set -x in the script.




Tags

Frequently Asked Question and Answer on Shell Scripting Bash

Shell Scripting Bash Interview Questions and Answers in PDF form Online

Shell Scripting Bash Questions with Answers

Shell Scripting Bash Trivia MCQ Quiz

FAQ Questions Sidebar

Related Topics


  • API Testing
  • Python
  • AWS Amazon Web Services
  • Java
  • C++
  • JavaScript
  • C#
  • PHP
  • Swift
  • Ruby
  • Kotlin
  • TypeScript
  • Go Golang
  • Rust
  • SQL
  • R
  • MATLAB
  • Perl
  • Scala
  • Dart
  • Haskell
  • Objective-C
  • Shell Scripting Bash
  • Visual Basic VB
  • Lua
  • Groovy
  • F#
  • Julia
  • COBOL
  • Fortran
  • Assembly Language
  • PL/SQL
  • Scratch
  • D
  • Erlang
  • Elixir
  • Clojure
  • Pascal
  • Ada
  • Lisp Common Lisp, Scheme
  • Prolog
  • Apex Salesforce
  • ActionScript
  • ABAP SAP
  • Racket
  • Nim
  • Crystal
  • Smalltalk
  • VHDL
  • Verilog
  • SASS Syntactically Awesome Style Sheets
  • Less CSS Preprocessor
  • CoffeeScript
  • J Sharp
  • Tcl (Tool Command Language)
  • XQuery
  • XSLT
  • OpenCL
  • CUDA
  • OpenGL Shader Language (GLSL)
  • VBScript
  • Solidity (Blockchain/Smart Contracts)
  • Yaml
  • JSON
  • XML
  • GDScript (Godot Engine)
  • UnrealScript (Unreal Engine)
  • Maple
  • Mathematica
  • Max/MSP
  • AutoLISP
  • LabVIEW
  • ScratchJr
  • AWK
  • sed (Stream Editor)
  • PostScript
  • Xojo
  • Q Sharp
  • Ring
  • ActionScript 3
  • OpenEdge ABL
  • RPG (IBM)
  • Inform
  • Modula-3
  • Rebol
  • Tcl/Tk
  • Haxe
  • SML (Standard ML)
  • Eiffel
  • Chapel
  • Red
  • MUMPS
  • PASCAL ABC
  • Icon
  • BCPL
  • Simula
  • SNOBOL
  • Hack (Meta)
  • PowerShell
  • Batch Script
  • AppleScript
  • Glue
  • Oz
  • Io
  • Mercury
  • Wren
  • Genie
  • PureScript
  • MoonScript
  • Turing
  • ALGOL
  • Seed7
  • Kotlin Native
  • Kotlin Multiplatform
  • Elm
  • PureBasic
  • QB64 (QuickBASIC)
  • Nemerle
  • Ocaml
  • Alloy
  • Cobra
  • Forth
  • Ballerina
  • Deno (JavaScript Runtime)
  • WASM (WebAssembly)
  • Z shell (Zsh)
  • Fish Shell
  • Redscript
  • Felix
  • ReScript
  • Agda
  • Idris
  • Coq
  • SPARK
  • Vala
  • PicoLisp
  • Wolfram Language
  • BASH (Bourne Again Shell)
  • Hy (Lisp-like for Python)
  • Terra
  • Boo
  • ATS
  • K (Kdb+)
  • Picat
  • Nimrod
  • Pawn
  • Papyrus (Bethesda Games)
  • J Programming Language
  • X++
  • MQL4/MQL5 (MetaTrader)
  • Transact-SQL (T-SQL)
  • BASH Shell Scripting

More Subjects


  • Computer Fundamentals
  • Data Structure
  • Programming Technologies
  • Software Engineering
  • Artificial Intelligence and Machine Learning
  • Cloud Computing

All Categories


  • Physics
  • Electronics Engineering
  • Electrical Engineering
  • General Knowledge
  • NCERT CBSE
  • Kids
  • History
  • Industry
  • World
  • Computer Science
  • Chemistry

Can't Find Your Question?

If you cannot find a question and answer in the knowledge base, then we request you to share details of your queries to us Suggest a Question for further help and we will add it shortly in our education database.
© 2025 Copyright InterviewQuizz. Developed by Techgadgetpro.com
Privacy Policy