Interview Quizz Logo

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

BASH Shell Scripting Questions and Answers for Viva

Frequently asked questions and answers of BASH Shell Scripting in Programming Technologies of Computer Science to enhance your skills, knowledge on the selected topic. We have compiled the best BASH Shell Scripting Interview question and answer, trivia quiz, mcq questions, viva question, quizzes to prepare. Download BASH Shell Scripting 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 BASH Shell Scripting


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

Answer-1: var_name="value" (no spaces around =).



Question-2. How do you access a variable in Bash?

Answer-2: Use $var_name or ${var_name}.



Question-3. How do you take user input in Bash?

Answer-3: read variable_name.



Question-4. How do you pass arguments to a Bash script?

Answer-4: Use $1, $2, ..., $n for positional arguments.



Question-5. How do you print output in Bash?

Answer-5: Use echo "Hello" or printf "Hello\n".



Question-6. How do you check the number of arguments passed to a script?

Answer-6: Use $# to get the count.



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

Answer-7: if [ condition ]; then commands; fi



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

Answer-8: if [ -f filename ]; then echo "Exists"; fi



Question-9. How do you check if a directory exists in Bash?

Answer-9: if [ -d dirname ]; then echo "Exists"; fi



Question-10. How do you use an else statement in Bash?

Answer-10: if [ condition ]; then commands; else other_commands; fi



Question-11. How do you write an elif statement in Bash?

Answer-11: if [ condition ]; then commands; elif [ condition ]; then commands; fi



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

Answer-12: [[ ]] supports advanced pattern matching and logical operations.



Question-13. How do you perform arithmetic operations in Bash?

Answer-13: Use expr, $(( expression )), or let.



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

Answer-14: for i in {1..5}; do echo $i; done



Question-15. How do you use a while loop in Bash?

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



Question-16. How do you break out of a loop in Bash?

Answer-16: Use break.



Question-17. How do you skip an iteration in a loop?

Answer-17: Use continue.



Question-18. How do you define a function in Bash?

Answer-18: function_name() { commands; }



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

Answer-19: function_name



Question-20. How do you return a value from a function?

Answer-20: Use return or echo and capture it with $( ).



Question-21. How do you get the exit status of a command?

Answer-21: Use $? (0 for success, nonzero for failure).



Question-22. How do you make a script executable?

Answer-22: chmod +x script.sh



Question-23. How do you append text to a file?

Answer-23: echo "text" >> file.txt



Question-24. How do you write text to a file (overwrite)?

Answer-24: echo "text" > file.txt



Question-25. How do you read a file line by line in Bash?

Answer-25: while read line; do echo "$line"; done < file.txt



Question-26. How do you check if a command succeeded?

Answer-26: if command; then echo "Success"; fi



Question-27. How do you find the length of a string in Bash?

Answer-27: echo ${#var}



Question-28. How do you extract a substring in Bash?

Answer-28: ${var:start:length}



Question-29. How do you replace text in a variable?

Answer-29: echo ${var/old/new}



Question-30. How do you convert a string to uppercase in Bash?

Answer-30: echo ${var^^}



Question-31. How do you convert a string to lowercase in Bash?

Answer-31: echo ${var,,}



Question-32. How do you list all environment variables?

Answer-32: Use env or printenv.



Question-33. How do you export a variable in Bash?

Answer-33: Use export VAR_NAME=value.



Question-34. How do you check if a command exists in Bash?

Answer-34: command -v command_name



Question-35. How do you check disk usage in Bash?

Answer-35: Use df -h.



Question-36. How do you check memory usage in Bash?

Answer-36: Use free -m.



Question-37. How do you schedule a script to run later?

Answer-37: Use cron (crontab -e).



Question-38. How do you find and delete files older than 7 days?

Answer-38: find /path -type f -mtime +7 -delete



Question-39. How do you kill a process in Bash?

Answer-39: Use kill PID or pkill process_name.



Question-40. How do you display running processes?

Answer-40: Use ps aux or top.



Question-41. How do you check open network ports?

Answer-41: Use netstat -tulnp or ss -tulnp.



Question-42. How do you extract the filename from a path?

Answer-42: basename /path/to/file.txt



Question-43. How do you extract the directory from a path?

Answer-43: dirname /path/to/file.txt



Question-44. How do you rename a file in Bash?

Answer-44: mv oldname newname



Question-45. How do you compress a file in Bash?

Answer-45: Use tar -czvf archive.tar.gz file



Question-46. How do you extract a .tar.gz file?

Answer-46: tar -xzvf archive.tar.gz



Question-47. How do you print system uptime?

Answer-47: Use uptime.



Question-48. How do you get the current date and time?

Answer-48: Use date or date +"%Y-%m-%d %H:%M:%S".



Question-49. What is Bash?

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



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

Answer-50: Use bash script.sh or chmod +x script.sh && ./script.sh.




Tags

Frequently Asked Question and Answer on BASH Shell Scripting

BASH Shell Scripting Interview Questions and Answers in PDF form Online

BASH Shell Scripting Questions with Answers

BASH Shell Scripting 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