Frequently asked questions and answers of BASH (Bourne Again Shell) in Programming Technologies of Computer Science to enhance your skills, knowledge on the selected topic. We have compiled the best BASH (Bourne Again Shell) Interview question and answer, trivia quiz, mcq questions, viva question, quizzes to prepare. Download BASH (Bourne Again Shell) 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.
Question-1. What is BASH?
Answer-1: BASH (Bourne Again Shell) is a Unix shell and command language used for scripting and system administration.
Question-2. Who developed BASH?
Answer-2: BASH was developed by the GNU Project as a free software replacement for the Bourne Shell (sh).
Question-3. How do you create a variable in BASH?
Answer-3: Using VAR_NAME=value, e.g., name="John".
Question-4. How do you print a variable in BASH?
Answer-4: Using echo, e.g., echo $name.
Question-5. What is the difference between $VAR and ${VAR}?
Answer-5: Both reference a variable, but ${VAR} helps avoid ambiguity.
Question-6. How do you get user input in BASH?
Answer-6: Using read, e.g., read name; echo "Hello, $name".
Question-7. How do you define a function in BASH?
Answer-7: Using function myFunc() { commands; } or myFunc() { commands; }.
Question-8. How do you call a function in BASH?
Answer-8: Simply by using the function name, e.g., myFunc.
Question-9. How do you execute a BASH script?
Answer-9: Using bash script.sh or ./script.sh (if executable).
Question-10. How do you make a script executable?
Answer-10: Using chmod +x script.sh.
Question-11. What is the shebang (#!) in BASH?
Answer-11: It specifies the interpreter, e.g., #!/bin/bash at the start of the script.
Question-12. How do you use command-line arguments in BASH?
Answer-12: Using $1, $2, etc., e.g., echo "First arg: $1".
Question-13. What does $@ and $* do in BASH?
Answer-13: Both represent all command-line arguments, but $@ preserves arguments as separate words.
Question-14. How do you check if a command was successful?
Answer-14: Using $?, where 0 means success.
Question-15. How do you use an if statement in BASH?
Answer-15: if [ condition ]; then commands; fi.
Question-16. How do you check if a file exists?
Answer-16: Using [ -f filename ], e.g., if [ -f myfile ]; then echo "Exists"; fi.
Question-17. How do you check if a directory exists?
Answer-17: Using [ -d dirname ], e.g., if [ -d mydir ]; then echo "Exists"; fi.
Question-18. How do you use a for loop in BASH?
Answer-18: for i in 1 2 3; do echo $i; done.
Question-19. How do you use a while loop in BASH?
Answer-19: while [ condition ]; do commands; done.
Question-20. How do you use a case statement in BASH?
Answer-20: case $var in pattern1) commands;; pattern2) commands;; esac.
Question-21. What is the difference between = and == in BASH?
Answer-21: = is for assignment, while == is used in string comparison.
Question-22. How do you redirect output to a file?
Answer-22: Using command > file (overwrite) or command >> file (append).
Question-23. How do you redirect errors to a file?
Answer-23: Using command 2> file or command 2>> file.
Question-24. How do you redirect both output and error to a file?
Answer-24: Using command > file 2>&1.
Question-25. How do you list all environment variables?
Answer-25: Using printenv or env.
Question-26. How do you export a variable in BASH?
Answer-26: Using export VAR=value.
Question-27. What is the difference between local and export in BASH?
Answer-27: local defines variables within a function, while export makes them available to child processes.
Question-28. How do you find the path of a command?
Answer-28: Using which command or type command.
Question-29. How do you check the number of arguments passed?
Answer-29: Using $#, e.g., echo "Arguments: $#"
Question-30. How do you read a file line by line in BASH?
Answer-30: while read line; do echo $line; done < file.txt.
Question-31. What does set -e do in a script?
Answer-31: It makes the script exit immediately on error.
Question-32. What does set -x do in a script?
Answer-32: It enables debugging by printing each command before executing it.
Question-33. How do you execute a command stored in a variable?
Answer-33: Using eval, e.g., cmd="ls -l"; eval $cmd.
Question-34. How do you run a command in the background?
Answer-34: Using command &.
Question-35. How do you bring a background job to the foreground?
Answer-35: Using fg.
Question-36. How do you kill a process in BASH?
Answer-36: Using kill PID or pkill process_name.
Question-37. How do you find all running processes?
Answer-37: Using ps aux or top.
Question-38. What is the difference between > and >>?
Answer-38: > overwrites a file, while >> appends to it.
Question-39. How do you check disk usage?
Answer-39: Using df -h or du -sh folder_name.
Question-40. How do you check memory usage?
Answer-40: Using free -h.
Question-41. What does && and `
Answer-41:
Question-42. How do you search for a string in a file?
Answer-42: Using grep "pattern" filename.
Question-43. How do you replace text in a file?
Answer-43: Using sed, e.g., sed -i 's/old/new/g' file.txt.
Question-44. How do you count lines in a file?
Answer-44: Using wc -l filename.
Question-45. How do you list only directories?
Answer-45: Using ls -d */.
Question-46. How do you find the current shell?
Answer-46: Using echo $SHELL.
Question-47. How do you check if a user is root?
Answer-47: Using if [ $(id -u) -eq 0 ]; then echo "Root user"; fi.
Question-48. How do you schedule a cron job?
Answer-48: Using crontab -e and adding * * * * * command.
Question-49. How do you create an alias?
Answer-49: Using alias name='command', e.g., alias ll='ls -la'.
Question-50. How do you remove an alias?
Answer-50: Using unalias name, e.g., unalias ll.
Frequently Asked Question and Answer on BASH (Bourne Again Shell)
BASH (Bourne Again Shell) Interview Questions and Answers in PDF form Online
BASH (Bourne Again Shell) Questions with Answers
BASH (Bourne Again Shell) Trivia MCQ Quiz