Unix Shell Scripting Interview Questions & Answers

  1. Question 1. What Is A Shell?

    Answer :

    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. Question 2. What Is Shell Scripting?

    Answer :

    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. Question 3. What Is The Importance Of Writing Shell Scripts?

    Answer :

    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. Question 4. Shell Programs Are Stored In Which File?

    Answer :

    Shell programs are stored in a file called sh.

  6. Perl Scripting Tutorial

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

    Answer :

    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. Question 6. What Are The Advantages Of C Shell Over Bourne Shell?

    Answer :

    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. Question 7. How Many Fields Are Present In A Crontab File And What Does Each Field Specify?

    Answer :

    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. Question 8. Is Separate Compiler Required For Executing A Shell Program?

    Answer :

    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. Question 9. How Many Shell Scripts Come With Unix Operating System?

    Answer :

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

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

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

    Answer :

    • 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. Question 11. Basis Of Shell Program Relies On What Fact?

    Answer :

    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. Question 12. What Are The Default Permissions Of A File When It Is Created?

    Answer :

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

  20. Perl Scripting Interview Questions

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

    Answer :

    File permissions can be modified using umask.

  22. Unix/Linux Tutorial

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

    Answer :

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

  24. Question 15. What Are Shell Variables?

    Answer :

    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. Question 16. What Are The Two Types Of Shell Variables? Explain In Brief?

    Answer :

    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.

    Example: 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

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

  27. Unix socket Tutorial

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

    Answer :

    Shell variables are stored as string variables.

    Example: $ 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. Question 18. What Is The Lifespan Of A Variable Inside A Shell Script?

    Answer :

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

  31. Shell Scripting Interview Questions

  32. Question 19. How To Make Variables As Unchangeable?

    Answer :

    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. Question 20. How Variables Can Be Wiped Out?

    Answer :

    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.

    CAUTION: Be careful while using this unset command.

  35. Unix/Linux Interview Questions

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

    Answer :

    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.

    Example: $ 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. Question 22. What Does The. (dot) Indicate At The Beginning Of A File Name And How Should It Be Listed?

    Answer :

    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. Question 23. What Is The Difference Between Diff And Cmp Commands?

    Answer :

    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. Question 24. By Default, A New File And A New Directory Which Is Being Created Will Have How Many Links?

    Answer :

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

  41. Autosys Interview Questions

  42. Question 25. What Is A File System?

    Answer :

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

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

    Answer :

    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. Question 27. What Are The Three Editors Available In Almost All The Versions Of Unix?

    Answer :

    The three editors are ed, ex & vi.

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

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

    Answer :

    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. Question 29. What Is The Alternative Command Available To Echo And What Does It Do?

    Answer :

    tput is an alternative command to echo.

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

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

    Answer :

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

    echo $ #

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

    Answer :

    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. Question 32. What Are Loops And Explain Three Different Methods Of Loops In Brief?

    Answer :

    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. Question 33. What Is Ifs?

    Answer :

    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. Question 34. What Is A Break Statement And What Is It Used For?

    Answer :

    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. Question 35. What Is Continue Statement And What Is It Used For?

    Answer :

    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. Question 36. What Are The Two Files Of Crontab Command?

    Answer :

    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. Question 37. What Are The Different Commands Available To Check The Disk Usage?

    Answer :

    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. Question 38. What Is Shebang In A Shell Script?

    Answer :

    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.

    Example: #!/bin/bash

    The above line also tells which shell to use.