Shell Scripting Interview Questions and Answers
Intermediate / 1 to 5 years experienced level questions & answers
Ques 1. 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.
Ques 2. 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.
Ques 3. 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.
Ques 4. 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.
Ques 5. Explain the use of the `awk` command in shell scripting.
The `awk` command is used for pattern scanning and processing in a text file.
Ques 6. 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.
Ques 7. Explain the use of the `expr` command in shell scripting.
The `expr` command is used for evaluating expressions in shell scripts.
Ques 8. 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.
Ques 9. What is a here document in shell scripting?
A here document is a way to redirect input into a command or a file using <<.
Ques 10. What is the purpose of the `getopts` command in shell scripting?
The `getopts` command is used to parse command-line options in shell scripts.
Ques 11. Explain the use of the `declare` command in shell scripting.
The `declare` command is used to set attributes for variables in a shell script.
Ques 12. Explain the use of the `eval` command in shell scripting.
The `eval` command is used to evaluate a command or an expression.
Ques 13. 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.
Ques 14. Explain the use of the `select` statement in a shell script.
The `select` statement is used for creating simple menus in shell scripts.
Ques 15. 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.
Ques 16. 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.
Ques 17. 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.
Ques 18. 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.
Ques 19. 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.
Ques 20. 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.
Ques 21. 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.
Most helpful rated by users: