Interview Questions and Answers
Freshers / Beginner level questions & answers
Ques 1. What is a shebang line in a shell script?
A shebang line is a special comment that specifies the path to the interpreter for the script.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 2. How do you comment out multiple lines in a shell script?
You can use the `: ' comment ' :` syntax to comment out multiple lines.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 3. Explain the use of the `shift` command in a shell script.
The `shift` command is used to shift the positional parameters to the left.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 4. How can you check if a file exists in a shell script?
You can use the `test` command or the `[ -e file ]` syntax to check if a file exists.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 5. How do you read input from the user in a shell script?
You can use the `read` command to read input from the user.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 6. Explain the use of the `grep` command in shell scripting.
The `grep` command is used to search for a pattern in text files.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 7. How do you use the `for` loop in a shell script?
The `for` loop is used to iterate over a sequence of values or elements.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 8. Explain the purpose of the `case` statement in a shell script.
The `case` statement is used for multiple-choice decision-making in a shell script.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 9. What is the purpose of the `basename` command in shell scripting?
The `basename` command is used to strip directory and suffix from filenames.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 10. How can you check the status of the last command in a shell script?
You can use the `$?` variable to check the exit status of the last command.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 11. What is the purpose of the `export` command in shell scripting?
The `export` command is used to make environment variables available to child processes.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 12. How do you use the `while` loop in a shell script?
The `while` loop is used to repeatedly execute a block of statements as long as a condition is true.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 13. How do you check if a variable is set in a shell script?
You can use the `isset` or `[ -z $var ]` syntax to check if a variable is set.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 14. Explain the use of the `dirname` command in shell scripting.
The `dirname` command is used to extract the directory component of a pathname.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 15. How can you find the length of a string in a shell script?
You can use the `expr length $string` or `${#string}` syntax to find the length of a string.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 16. What is the purpose of the `printf` command in shell scripting?
The `printf` command is used for formatted printing in shell scripts.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 17. How do you use arithmetic operations in a shell script?
You can use the `expr` command or $((expression)) syntax for arithmetic operations.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 18. How do you check if a directory exists in a shell script?
You can use the `test` command or `[ -d directory ]` syntax to check if a directory exists.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 19. What is the purpose of the `shift` command in a shell script?
The `shift` command is used to shift the positional parameters to the left.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 20. How do you use the `case` statement in a shell script?
The `case` statement is used for multiple-choice decision-making in a shell script.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 21. What is the purpose of the `continue` statement in a shell script?
The `continue` statement is used to skip the rest of a loop's code and start the next iteration.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 22. Explain the use of the `grep` command in shell scripting.
The `grep` command is used to search for a pattern in text files.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 23. What is the purpose of the `echo` command in shell scripting?
The `echo` command is used to print messages or variables to the standard output.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 24. Explain the use of the `case` statement in a shell script.
The `case` statement is used for multiple-choice decision-making in a shell script.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 25. How do you use command substitution in a shell script?
Command substitution allows the output of a command to replace the command itself, and it can be done using `$(command)`.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 26. Explain the use of the `test` command in shell scripting.
The `test` command is used to evaluate expressions and conditions in shell scripts.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 27. What is the purpose of the `dirname` command in shell scripting?
The `dirname` command is used to extract the directory component of a pathname.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 28. How do you use the `if` statement in a shell script?
The `if` statement is used for conditional execution in a shell script.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Intermediate / 1 to 5 years experienced level questions & answers
Ques 29. Explain the difference between single and double brackets in conditional statements.
Single brackets are the traditional test command, while double brackets are an enhanced version with additional features.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 30. What is the purpose of the `set` command in a shell script?
The `set` command is used to change the behavior of the script by modifying shell options.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 31. What is the purpose of the `trap` command in a shell script?
The `trap` command is used to catch signals and execute a command when they occur.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 32. What is the purpose of the `cut` command in a shell script?
The `cut` command is used to extract specific columns or fields from a text file.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 33. Explain the use of the `awk` command in shell scripting.
The `awk` command is used for pattern scanning and processing in a text file.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 34. How do you redirect both standard output and standard error to the same file?
You can use `command > file 2>&1` to redirect both stdout and stderr to the same file.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 35. Explain the use of the `expr` command in shell scripting.
The `expr` command is used for evaluating expressions in shell scripts.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 36. Explain the use of the `tee` command in shell scripting.
The `tee` command is used to redirect output to multiple files and the standard output.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 37. What is a here document in shell scripting?
A here document is a way to redirect input into a command or a file using <<.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 38. What is the purpose of the `getopts` command in shell scripting?
The `getopts` command is used to parse command-line options in shell scripts.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 39. Explain the use of the `declare` command in shell scripting.
The `declare` command is used to set attributes for variables in a shell script.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 40. Explain the use of the `eval` command in shell scripting.
The `eval` command is used to evaluate a command or an expression.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 41. What is the purpose of the `cut` command in a shell script?
The `cut` command is used to extract specific columns or fields from a text file.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 42. Explain the use of the `select` statement in a shell script.
The `select` statement is used for creating simple menus in shell scripts.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 43. Explain the use of the `cut` command in a shell script.
The `cut` command is used to extract specific columns or fields from a text file.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 44. What is the purpose of the `trap` command in a shell script?
The `trap` command is used to catch signals and execute a command when they occur.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 45. How do you use the `sed` command in a shell script?
The `sed` command is used for stream editing and transformation in a shell script.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 46. How do you use the `find` command in a shell script?
The `find` command is used to search for files and directories based on various criteria.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 47. How do you use the `cut` command in a shell script?
The `cut` command is used to extract specific columns or fields from a text file.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 48. What is the purpose of the `awk` command in shell scripting?
The `awk` command is used for pattern scanning and processing in a text file.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 49. Explain the use of the `tee` command in shell scripting.
The `tee` command is used to redirect output to multiple files and the standard output.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Experienced / Expert level questions & answers
Ques 50. What is process substitution in shell scripting?
Process substitution allows a process's input or output to be referred to using a filename.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Most helpful rated by users: