Shell Scripting Interview Questions & Answers

  1. Question 1. What Are Pids?

    Answer :

    They are process IDs given to processes. A PID can vary from 0 to 65535.

  2. Question 2. How Do You Remove A File?

    Answer :

    “rm” removes each specified file argument (provided that it is a valid path name). If you specify either . or .. as the final component of the path name for a file, rm displays an error message, and moves onto the next file. If you specify a file you do not have write permission for, rm asks you for confirmation.

  3. Perl Scripting Interview Questions

  4. Question 3. How Do You Remove Recursively?

    Answer :

    rm -rf.

  5. Question 4. How Do You Find Out Your Own Username?

    Answer :

    whoami.

  6. Perl Scripting Tutorial

  7. Question 5. How Do You Count Words, Lines And Characters In A File?

    Answer :

    wc

  8. Python Interview Questions

  9. Question 6. How Do You Search For A String Inside A Given File?

    Answer :

    grep string filename.

  10. Question 7. How Do You Search For A String Inside A Directory?

    Answer :

    grep string *.

  11. Python Tutorial
    Linux Interview Questions

  12. Question 8. How Do You Search For A String In A Directory With The Subdirectories Recursed?

    Answer :

    grep -r string *.

  13. Question 9. How Do You List Currently Running Process?

    Answer :

    PS.

  14. Linux Embedded systems Interview Questions

  15. Question 10. How Do You Find Out What’s Your Shell?

    Answer :

    echo $SHELL.

  16. Linux Tutorial

  17. Question 11. How Do You Fire A Process In The Background?

    Answer :

    ./process-name &.

  18. AWK Interview Questions

  19. Question 12. What’s The Conditional Statement In Shell Scripting?

    Answer :

    if {condition} then …… fi.

  20. Perl Scripting Interview Questions

  21. Question 13. How Do You Do Number Comparison In Shell Scripts?

    Answer :

    -eq, -ne, -lt, -le, -gt, -ge.

  22. Linux Embedded systems Tutorial

  23. Question 14. How Do You Test For File Properties In Shell Scripts?

    Answer :

    -s filename tells you if the file is not empty,
    -f filename tells you whether the argument is a file, and not a directory,
    -d filename tests if the argument is a directory, and not a file,
    -w filename tests for writeability,
    -r filename tests for readability.
    -x filename tests for executability

  24. Question 15. How Do You Do Boolean Logic Operators In Shell Scripting?

    Answer :

    tests for logical not, -a tests for logical and, and -o tests for logical or.

  25. BioPerl Interview Questions

  26. Question 16. How Do You Find Out The Number Of Arguments Passed To The Shell Script?

    Answer :

    S$

  27. AWK Tutorial

  28. Question 17. What’s The Way To Do Multilevel If-else’s In Shell Scripting?

    Answer :

    if {condition} then {staternent} elif {condition} {statement} fi.

  29. Sed (Stream Editor) Interview Questions

  30. Question 18. How Do You Write A For Loop In Shell?

    Answer :

    for {variable name} in {list} do {statement} done.

  31. Python Interview Questions

  32. Question 19. How Do You Find Out The Current Directory You’re In?

    Answer :

    pwd.

  33. Sed (Stream Editor) Tutorial

  34. Question 20. What’s The Command To Find Out Users On The System?

    Answer :

    who.

  35. Advanced Linux Interview Questions

  36. Question 21. What’s The Command To Find Out Today’s Date?

    Answer :

    date.

  37. Question 22. How Do You Stop A Process?

    Answer :

    kill pid.

  38. Unix/Linux Tutorial

  39. Question 23. How Do You Find Out About All Running Processes?

    Answer :

    ps -ag.

  40. Unix/Linux Interview Questions

  41. Question 24. How Do You Stop All The Processes, Except The Shell Window?

    Answer :

    kill 0.

  42. Linux Interview Questions

  43. Question 25. How Do You Define A Function In A Shell Script?

    Answer :

    function-narne() { #some code here return }.

  44. Question 26. How Do You Read Keyboard Input In Shell Scripts?

    Answer :

    read { variable-name}.

  45. Unix Shell Scripting Interview Questions

  46. Question 27. How Does A Case Statement Look In Shell Scripts?

    Answer :

    case { variable} in {possible-value-1} {statement} ;; {possible-value-2}) {statement};; esac.

  47. Linux Embedded systems Interview Questions

  48. Question 28. How Do You Write A While Loop In Shell?

    Answer :

    while {condition} do {statement} done.

  49. Question 29. What Is Shell Scripting?

    Answer :

    Shell scripting is used to program command line of an operating system. Shell Scripting is also used to program the shell which is the base for any operating system. Shell scripts often refer to programming UNIX. Shell scripting is mostly used to program operating systems of windows, UNIX, Apple, etc. Also this script is used by companies to develop their own operating system with their own features.

  50. Question 30. State The Advantages Of Shell Scripting?

    Answer :

    There are many advantages of shell scripting some of them are, one can develop their own operating system with relevant features best suited to their organization than to rely on costly operating systems. Software applications can be designed according to their platform.

  51. Question 31. What Are The Disadvantages Of Shell Scripting?

    Answer :

    There are many disadvantages of shell scripting they are

    • Design flaws can destroy the entire process and could prove a costly error.
    • Typing errors during the creation can delete the entire data as well as partition data.
    • Initially process is slow but can be improved.
    • Portbility between different operating system is a prime concern as it is very difficult to port scripts etc.
  52. Question 32. Explain About The Slow Execution Speed Of Shells?

    Answer :

    Major disadvantage of using shell scripting is slow execution of the scripts. This is because for every command a new process needs to be started. This slow down can be resolved by using pipeline and filter commands. A complex script takes much longer time than a normal script.

  53. Question 33. Give Some Situations Where Typing Error Can Destroy A Program?

    Answer :

    There are many situations where typing errors can prove to be a real costly effort. For example a single extra space can convert the functionality of the program from deleting the sub directories to files deletion. cp, cn, cd all resemble the same but their actual functioning is different. Misdirected > can delete your data.

  54. AWK Interview Questions

  55. Question 34. Explain About Return Code?

    Answer :

    Return code is a common feature in shell programming. These return codes indicate whether a particular program or application has succeeded or failed during its process. && can be used in return code to indicate which application needs to be executed first.

  56. Question 35. What Are The Different Variables Present In Linux Shell?

    Answer :

    Variables can be defined by the programmer or developer they specify the location of a particular variable in the memory. There are two types of shells they are System variables and user defined variables. System variables are defined by the system and user defined variables are to be defined by the user (small letters).

  57. Question 36. Explain About Gui Scripting?

    Answer :

    Graphical user interface provided the much needed thrust for controlling a computer and its applications. This form of language simplified repetitive actions. Support for different applications mostly depends upon the operating system. These interact with menus, buttons, etc.

  58. BioPerl Interview Questions

  59. Question 37. Explain About Echo Command?

    Answer :

    Echo command is used to display the value of a variable. There are many different options give different outputs such as usage c suppress a trailing line, r returns a carriage line, -e enables interpretation, r returns the carriage.

  60. Question 38. Explain About Stdin, Stdout And Stderr?

    Answer :

    These are known as standard input, output and error. These are categorized as 0, 1 and 2. Each of these functions has a particular role and should accordingly functions for efficient output. Any mismatch among these three could result in a major failure of the shell.

  61. Question 39. Explain About Sourcing Commands?

    Answer :

    Sourcing commands help you to execute the scripts within the scripts. For example sh command makes your program to run as a separate shell. .command makes your program to run within the shell. This is an important command for beginners and for special purposes.

  62. Question 40. Explain About Debugging?

    Answer :

    Shell can make your debugging process easier because it has lots of commands to perform the function. For example sh –n command helps you to perform debugging. It helps you to read the shell but not to execute it during the course. Similarly sh –x command helps you by displaying the arguments and functions as they are executed.

  63. Sed (Stream Editor) Interview Questions

  64. Question 41. Explain About Login Shell?

    Answer :

    Login shell is very useful as it creates an environment which is very useful to create the default parameters. It consists of two files they are profile files and shell rc files. These files initialize the login and non login files. Environment variables are created by Login shell.

  65. Question 42. Explain About Non-login Shell Files?

    Answer :

    The non login shell files are initialized at the start and they are made to run to set up variables. Parameters and path can be set etc are some important functions. These files can be changed and also your own environment can be set. These functions are present in the root. It runs the profile each time you start the process.

  66. Advanced Linux Interview Questions

  67. Question 43. Explain About Shebang?

    Answer :

    Shebang is nothing but a # sign followed by an exclamation. This is visible at the top of the script and it is immediately followed by an exclamation. To avoid repetitive work each time developers use shebang. After assigning the shebang work we pass info to the interpreter.

  68. Question 44. Explain About The Exit Command?

    Answer :

    Every program whether on UNIX or Linux should end at a certain point of time and successful completion of a program is denoted by the output 0. If the program gives an output other than 0 it defines that there has been some problem with the execution or termination of the problem. Whenever you are calling other function, exit command gets displayed.

  69. Question 45. Explore About Environment Variables?

    Answer :

    Environment variables are set at the login time and every shell that starts from this shell gets a copy of the variable. When we export the variable it changes from an shell variable to an environment variable and these variables are initiated at the start of the shell

  70. Question 46. How Do You Read Keyboard Input In Shell Scripts?

    Answer :

    This is the way to read values into your shell script variables from keyboard input.

    #!/bin/bash
    read name
    echo "Hello $name"
  71. Question 47. What Is The Difference Between Writing Code In Shell And Editor?

    Answer :

    Code in the script (Shell is interpreted) as shell is a interpreter where as editor is not interpreter certain set of commands(predefined) are used to handle editor.