300+ TOP Unix Shell Scripting Interview Questions – Answers

  1. 1. What Is A Shell?

    Shell is a command interpreter, which interprets the command which the user gives to the kernel. It can also be defined as an interface between a user and operating system.

  2. 2. What Is Shell Scripting?

    Shell scripting is nothing but series or sequence of UNIX commands written in a plain text file. Instead of specifying one job/command at a time, in shell scripting we give a list of UNIX commands like a to-do list in a file to execute it.

  3. Perl Scripting Interview Questions

  4. 3. What Is The Importance Of Writing Shell Scripts?

    The points given below explain the importance of writing shell scripts.

    • Shell script takes input from the user, file and displays it on the screen.
    • Shell scripting is very useful in creating your own commands.
    • It is helpful in automating some tasks of the day to day life.
    • It is useful for automating system administration tasks.
    • Mainly it saves time.
  5. 4. Shell Programs Are Stored In Which File?

    Shell programs are stored in a file called sh.

  6. Perl Scripting Tutorial

  7. 5. What Are The Different Types Of Shells Available?

    There are mainly 4 important types of shells that are widely used.

    And they include:

    • Bourne Shell (sh)
    • C Shell (csh)
    • Korn Shell (ksh)
    • Bourne Again Shell (bash)

  8. Shell Scripting Interview Questions

  9. 6. What Are The Advantages Of C Shell Over Bourne Shell?

    The advantages of C Shell over Bourne Shell are:

    • C shell allows aliasing of commands i.e. a user can give any name of his choice to the command. This feature is mainly useful when a user has to type the lengthy command again and again. At that point of time, instead of typing a lengthy command a user can type the name that he has given.
    • C shell provides command history feature. C shell remembers the previously typed command. Thus, it avoids typing the command again and again.
  10. 7. How Many Fields Are Present In A Crontab File And What Does Each Field Specify?

    The crontab file has six fields. The first five fields tell cron when to execute the command: minute(0-59), hour(0-23), day(1-31), month(1-12), and day of the week(0-6, Sunday = 0).

    And the sixth field contains the command to be executed

  11. Shell Scripting Tutorial
    Autosys Interview Questions

  12. 8. Is Separate Compiler Required For Executing A Shell Program?

    A separate compiler is not required to execute a shell program. The shell itself interprets the command in the shell program and executes them.

  13. 9. How Many Shell Scripts Come With Unix Operating System?

    There are approximately 280 shell scripts that come with the UNIX operating system.

  14. Unix Inter-Process Communication (IPC) Interview Questions

  15. 10. When Should Shell Programming/scripting Not Be Used?

    • Generally, shell programming/scripting should not be used in the below instances.
    • When the task is very much complex like writing the entire payroll processing system.
    • Where there is a high degree of productivity required.
    • When it needs or involves different software tools.

  16. AWK Tutorial

  17. 11. Basis Of Shell Program Relies On What Fact?

    The basis of shell programming relies on the fact that UNIX shell can accept commands not just only from the keyboard but also from a file.

  18. UNIX Memory Management Interview Questions

  19. 12. What Are The Default Permissions Of A File When It Is Created?

    666 i.e. rw-rw-rw- is the default permission of a file when it is created.

  20. Perl Scripting Interview Questions

  21. 13. What Can Be Used To Modify File Permissions?

    File permissions can be modified using umask.

  22. Unix/Linux Tutorial

  23. 14. How To Accomplish Any Task Via Shell Script?

    Any task can be accomplished via shell script at the dollar ($) prompt and vice versa.

  24. 15. What Are Shell Variables?

    Shell variables are the main part of shell programming or scripting. They mainly provide the ability to store and manipulate information within a shell program.

  25. UNIX Process Management Interview Questions

  26. 16. What Are The Two Types Of Shell Variables? Explain In Brief?

    The two types of shell variables are:

    1) Unix Defined Variables or System Variables
    – These are standard or shell defined variables. Generally, they are defined in CAPITAL letters.

    SHELL – This is a Unix Defined or System Variable, which defines the name of the default working shell.

    2) User Defined Variables –
    These are defined by users. Generally, they are defined in lower letters

    $ a=10 –Here the user has defined a variable called ‘a’ and assigned value to it as 10.

  27. Unix socket Tutorial

  28. 17. How Are Shell Variables Stored? Explain With A Simple Example?

    Shell variables are stored as string variables.

    $ a=10

    In the above statement a=10, the 10 stored in ‘a’ is not treated as a number, but as a string of characters 1 and 0.

  29. AWK Interview Questions

  30. 18. What Is The Lifespan Of A Variable Inside A Shell Script?

    The lifespan of a variable inside shell script is only until the end of execution.

  31. Shell Scripting Interview Questions

  32. 19. How To Make Variables As Unchangeable?

    Variables can be made unchangeable using readonly. For instance, if we want variable a value to remain as 10 and not to be changed then we can achieve this using readonly.


    $ a=10

    $ readonly a

  33. Unix makefile Tutorial

  34. 20. How Variables Can Be Wiped Out?

    Variables can be wiped out or erased using the unset command.


    $ a =20

    $ unset a

    Upon using the above command the variable ‘a’ and its value 20 get erased from shell’s memory.

    Be careful while using this unset command.

  35. Unix/Linux Interview Questions

  36. 21. What Are Positional Parameters? Explain With An Example?

    Positional parameters are the variables defined by a shell. And they are used whenever we need to convey information to the program. And this can be done by specifying arguments at the command line.

    There are totally 9 positional parameters present i.e. from $1 to $9.

    $ Test Indian IT Industry has grown very much faster

    In the above statement, positional parameters are assigned like this.

    $0 -> Test (Name of a shell program/script)

    $1 ->Indian

    $2 -> IT and so on.

  37. 22. What Does The. (dot) Indicate At The Beginning Of A File Name And How Should It Be Listed?

    A file name which begins with a .(dot) is called as a hidden file. Whenever we try to list the files it will list all the files except hidden file.

    But it will be present in the directory. And to list the hidden file we need to use –a option of ls. i.e. $ ls –a.

  38. 23. What Is The Difference Between Diff And Cmp Commands?

    diff –
    Basically, it tells about the changes which need to be made to make files identical.

    cmp –
    Basically it compares two files byte by byte and displays the very first mismatch.

  39. Unix socket Interview Questions

  40. 24. By Default, A New File And A New Directory Which Is Being Created Will Have How Many Links?

    New file contains one link. And a new directory contains two links.

  41. Autosys Interview Questions

  42. 25. What Is A File System?

    The file system is a collection of files which contain related information of the files.

  43. 26. What Are The Three Different Security Provisions Provided By Unix For A File Or Data?

    Three different security provisions provided by UNIX for a file or data are:

    • It provides a unique user id and password to the user, so that unknown or unauthorized person should not be able to access it.
    • At file level, it provides security by providing read, write & execute permissions for accessing the files.
    • Lastly, it provides security using file encryption. This method allows encoding a file in an unreadable format. Even if someone succeeds in opening a file, but they cannot read its contents until and unless it is decrypted

  44. Unix Production Support Interview Questions

  45. 27. What Are The Three Editors Available In Almost All The Versions Of Unix?

    The three editors are ed, ex & vi.

  46. Unix Inter-Process Communication (IPC) Interview Questions

  47. 28. What Are The Three Modes Of Operation Of Vi Editor? Explain In Brief?

    The three modes of operation of vi editors are:

    • Command Mode:
      In this mode, all the keys pressed by a user are interpreted as editor commands.
    • Insert Mode:
      This mode allows for insertion of a new text and editing of an existing text etc.
    • The ex-command Mode:
      This mode allows a user to enter the commands at a command line.
  48. 29. What Is The Alternative Command Available To Echo And What Does It Do?

    tput is an alternative command to echo.

    Using this, we can control the way in which the output is displayed on the screen.

  49. 30. How To Find Out The Number Of Arguments Passed To The Script?

    The number of arguments passed to the script can be found as shown below.

    echo $ #

  50. 31. What Are Control Instructions And How Many Types Of Control Instructions Are Available In A Shell? Explain In Brief.

    Control Instructions are the ones, which enable us to specify the order in which the various instructions in a program/script are to be executed by the computer. Basically, they determine a flow of control in a program.

    There are 4 types of control instructions that are available in a shell:

    Sequence Control Instruction
    – This ensures that the instructions are executed in the same order in which they appear in the program.

    Selection or Decision Control Instruction
    – It allows the computer to take a decision as to which instruction is to be executed next.

    Repetition or Loop Control Instruction
    – It helps a computer to execute a group of statements repeatedly.

    Case-Control Instruction
    – This is used when we need to select from several alternatives.

  51. 32. What Are Loops And Explain Three Different Methods Of Loops In Brief?

    Loops are the ones, which involve repeating some portion of the program/script either a specified number of times or until a particular condition is being satisfied.

    3 methods of loops are:

    For loop
    – This is the most commonly used loop. For loop allows specifying a list of values which the control variable in the loop can take. The loop is then executed for each value mentioned in the list.

    While loop
    – This is used in a program when we want to do something for a fixed number of times. While loop gets executed till it returns a zero value.

    Until loop
    – This is similar to while loop except that the loop executes until the condition is true. Until loop gets executed at least once till it returns a non-zero value.

  52. 33. What Is Ifs?

    IFS stands for Internal Field Separator. And it is one of the system variables. By default, its value is space, tab, and a new line.

    It signifies that in a line where one field or word ends and another begins.

  53. UNIX Memory Management Interview Questions

  54. 34. What Is A Break Statement And What Is It Used For?

    The break is a keyword and is used whenever we want to jump out of a loop instantly without waiting to get back to the control command.

    When the keyword break is encountered inside any loop in the program, control will get passed automatically to the first statement after a loop. A break is generally associated with an if.

  55. 35. What Is Continue Statement And What Is It Used For?

    Continue is a keyword and is used whenever we want to take the control to the beginning of the loop, by passing the statements inside the loop which have not yet been executed.

    When the keyword continue is encountered inside any loop in the program, control automatically passes to the beginning of a loop. Continue is generally associated with an if.

  56. 36. What Are The Two Files Of Crontab Command?

    Two files of crontab command are:

    cron.allow –
    It decides which users need to be permitted from using crontab command.

    cron.deny –
    It decides which users need to be prevented from using crontab command.

  57. UNIX Process Management Interview Questions

  58. 37. What Are The Different Commands Available To Check The Disk Usage?

    There are three different commands available to check the disk usage.

    And they are:

    df –
    This command is used to check the free disk space.

    du –
    This command is used to check the directory wise disk usage.

    dfspace –
    This command is used to check the free disk space in terms of MB.

  59. 38. What Is Shebang In A Shell Script?

    Shebang is a # sign followed by an exclamation i.e. !. Generally, this can be seen at the beginning or top of the script/program. Usually, a developer uses this to avoid repetitive work. Shebang mainly determines the location of the engine which is to be used in order to execute the script.

    Here ‘#’ symbol is called as hash and ‘!’ is called a bang.


    The above line also tells which shell to use.