Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

101.

test command can be used to check which of the following?(a) Compare two numbers(b) Compare two strings(c) Check attributes of a file(d) All of the mentionedI had been asked this question in an interview for job.The query is from Using test and [ ] to Evaluate Expressions in division Essential Shell Programming of Unix

Answer» CORRECT answer is (d) All of the mentioned

To explain I would say: When we use if to evaluate expressions, we need the test statement because the true or false values RETURNED by expressions can’t be directly handled by if. The test uses certain operators to evaluate the condition on its right and returns EITHER true or false exit status. test works in three ways:

•compares two numbers

•compare two strings or a SINGLE ONE for a null value

•check a file’s attributes
102.

To check more than two conditions, ___ is used with if-else statements.(a) while(b) for(c) elif(d) forI have been asked this question in an interview for internship.I want to ask this question from Logical Operators and Conditional Execution in chapter Essential Shell Programming of Unix

Answer»

Correct choice is (c) elif

Easiest EXPLANATION: if-else STATEMENTS MAKES TWO-way decisions depending on the fulfillment of certain CONDITIONS. But if we want to check more than two conditions we can use elif statement. For example,

103.

To know the exit status of a command, we can use ____(a) $$(b) $*(c) $?(d) $-The question was posed to me in quiz.My query is from Logical Operators and Conditional Execution topic in chapter Essential Shell Programming of Unix

Answer»

Right option is (c) $?

The EXPLANATION is: The parameter $? STORES the exit status of the last command. It displays the value if the command SUCCEEDS and a non ZERO value if it fails.

104.

The name of the script is stored in which special parameter?(a) Dollar 1(b) Dollar 0(c) Dollar #(d) Dollar *The question was posed to me in my homework.This interesting question is from Logical Operators and Conditional Execution topic in section Essential Shell Programming of Unix

Answer»

The correct option is (B) DOLLAR 0

The EXPLANATION is: There are some special parameters used by the shell. One of which is $0 which STORES the NAME of the program.

105.

To perform decision depending on the fulfillment of certain criteria, ____ is used.(a) if(b) else(c) for(d) if and elseThis question was addressed to me by my college professor while I was bunking the class.I'd like to ask this question from Logical Operators and Conditional Execution topic in section Essential Shell Programming of Unix

Answer» CORRECT OPTION is (d) if and else

To explain: The if and else STATEMENT makes two-way decisions depending on the FULFILLMENT of certain criteria. These statements are used in UNIX as they are used in other programming languages. For example,
106.

Every if is closed with a corresponding ____(a) else(b) fi(c) if(d) else ifThe question was posed to me in a job interview.I'd like to ask this question from Logical Operators and Conditional Execution topic in division Essential Shell Programming of Unix

Answer»

Right answer is (B) FI

The best I can explain: if and ELSE statements are used for making two-way decisions. Every if is CLOSED with the corresponding fi. If we don’t do this we’ll encounter an ERROR.

107.

The syntax for using && is ______________(a) cmd1 && cmd2(b) cmd1 cmd2 &&(c) cmd1 & cmd2&(d) cmd1I got this question during an internship interview.This interesting question is from Logical Operators and Conditional Execution in section Essential Shell Programming of Unix

Answer»

Correct CHOICE is (a) cmd1 && cmd2

To explain: The SHELL provides two OPERATORS that allow conditional EXECUTION –the && and ||. The syntax for using these operators is:

108.

Which of the following is used for storing the number of positional parameters?(a) $n(b) $#(c) $*(d) $2This question was addressed to me during an online exam.The origin of the question is Shell Programming using read Command and Command Line Arguments topic in division Essential Shell Programming of Unix

Answer»

Correct choice is (B) $#

To explain: $# is used for storing the NUMBER of arguments specified. It lets us design scripts that CHECK whether the right number of arguments have been ENTERED. For example, the FOLLOWING script shows the use of positional parameters:

109.

When we use ||, both the commands are executed.(a) True(b) FalseI got this question in an international level competition.My question is from Logical Operators and Conditional Execution topic in portion Essential Shell Programming of Unix

Answer»

Right option is (B) False

Best explanation: || is an operator used by the SHELL for CONDITIONAL execution. It plays an INVERSE role in which the second COMMAND is executed only when the first fails.

110.

When we use &&, the second command is executed only when first succeeds.(a) True(b) FalseThis question was posed to me during a job interview.My question is taken from Logical Operators and Conditional Execution in chapter Essential Shell Programming of Unix

Answer»

The CORRECT answer is (a) True

Explanation: The shell provides two operators that allow conditional EXECUTION, one of which is &&. It delimits two commands; the second COMMAND is EXECUTED only when the FIRST command succeeds.

111.

Which of the following operators are used for logical execution?(a) ||(b) &&(c) %%(d) && and ||I got this question in unit test.This interesting question is from Logical Operators and Conditional Execution topic in section Essential Shell Programming of Unix

Answer»

Right OPTION is (d) && and ||

The EXPLANATION: The operators && and || are used for LOGICAL EXECUTION i.e. they act as AND, OR CONDITION respectively. The syntax for using these operators is:

112.

A single read statement can be used with one or more variables.(a) True(b) FalseI have been asked this question in class test.This interesting question is from Shell Programming using read Command and Command Line Arguments in division Essential Shell Programming of Unix

Answer»

Correct choice is (a) True

The explanation: A SINGLE read STATEMENT can be used with one or more variables to let us enter multiple arguments. For EXAMPLE,

read FirstNameLastName

113.

The complete set of positional parameters is stored in ______ as a single string.(a) $n(b) $#(c) $*(d) $$This question was posed to me in an online interview.My doubt is from Shell Programming using read Command and Command Line Arguments in section Essential Shell Programming of Unix

Answer»

The correct ANSWER is (C) $*

The EXPLANATION: There are some special parameters USED by the shell. One of which is $*, which stores the complete set of POSITIONAL parameters as a single string.

114.

The first argument is read by the shell into the parameter ___(a) 1$(b) $3(c) $$(d) $1The question was asked during an interview.My question is taken from Shell Programming using read Command and Command Line Arguments topic in section Essential Shell Programming of Unix

Answer»

The CORRECT choice is (d) $1

To ELABORATE: COMMAND line arguments are stored into positional parameters. The first argument is read by the shell into the PARAMETER $1, second argument in $2 and so on.

115.

What are positional parameters?(a) special variables for assigning arguments from the command line(b) pattern matching parameters(c) special variables for reading user input(d) special variables and patternsThe question was asked in an international level competition.This interesting question is from Shell Programming using read Command and Command Line Arguments in division Essential Shell Programming of Unix

Answer» CORRECT option is (a) special variables for ASSIGNING arguments from the command line

For explanation: Shell scripts can also take INPUT from command line. When arguments are specified with a shell SCRIPT, they are ASSIGNED to certain special variables called positional parameters.
116.

read command is shell’s internal tool.(a) True(b) FalseThis question was posed to me in final exam.I would like to ask this question from Shell Programming using read Command and Command Line Arguments topic in section Essential Shell Programming of Unix

Answer»

Correct OPTION is (a) True

The explanation: read command is the shell’s internal tool for TAKING input from the USER i.e. it makes the scripts INTERACTIVE.

117.

To spawn a child of our own choice for running the script, we can use ___ command.(a) ps(b) pr(c) sh(d) $$I got this question by my college professor while I was bunking the class.Origin of the question is Shell Programming using read Command and Command Line Arguments topic in division Essential Shell Programming of Unix

Answer»

Correct choice is (c) sh

The EXPLANATION: We know that shell SCRIPTS are executed by a child shell. But we can also explicitly SPAWN a child of our own choice by using the sh COMMAND along with script name as an argument. When used in this way, the interpreter LINE is ignored by the shell.

118.

To run the script, we should make it executable first by using _____(a) chmod +x(b) chmod +r(c) chmod +w(d) chmod +rwxI have been asked this question in examination.My question comes from Shell Programming using read Command and Command Line Arguments in chapter Essential Shell Programming of Unix

Answer»

The correct choice is (a) chmod +X

The BEST I can explain: Before we run the script, it is ESSENTIAL to make the script executable first. After that INVOKE the script NAME to run the script. For making the script executable, we have to use chmod +x script_name.

119.

The first line in any shell script begins with a _____(a) &(b) !(c) $(d) #I got this question in quiz.Question is taken from Shell Programming using read Command and Command Line Arguments topic in portion Essential Shell Programming of Unix

Answer» CORRECT answer is (d) #

For EXPLANATION I would say: When the comment character (#) is PLACED anywhere in a line; the shell ignores all characters on its right. However, this rule doesn’t apply to the first line which is the interpreter line. It always begins with #! and FOLLOWED by the pathname of the shell to be used for running the script.
120.

Which command is used for making the scripts interactive?(a) ip(b) input(c) read(d) writeThe question was asked in an interview for internship.My enquiry is from Shell Programming using read Command and Command Line Arguments in portion Essential Shell Programming of Unix

Answer»

The correct answer is (c) read

For explanation I WOULD SAY: read command is USED for making SCRIPTS INTERACTIVE. It is used for taking input from the user. Input supplied from the keyboard is entered into the variable used with the read command. For example,

121.

Shell scripts are executed in a separate child shell process.(a) True(b) FalseI have been asked this question in an internship interview.This key question is from Shell Programming using read Command and Command Line Arguments in section Essential Shell Programming of Unix

Answer»

Right option is (a) True

Easy explanation: Shell scripts are executed in a separate child process, and this sub-shell NEED not be of the same type as our login shell. In other words, EVEN if our login shell is bourne, we can USE a KORN sub-shell to run our SCRIPT.

122.

Shell scripts need to be saved with an extension .sh .(a) True(b) FalseI got this question in exam.This question is from Shell Programming using read Command and Command Line Arguments topic in division Essential Shell Programming of Unix

Answer»

Right option is (b) False

For EXPLANATION: It’s not mandatory to save SCRIPT files with .SH extension but we do so for our own convention as it makes it easy to MATCH them with WILDCARDS.

123.

What is a shell script?(a) group of commands(b) a file containing special symbols(c) a file containing a series of commands(d) group of functionsI had been asked this question in homework.My question is based upon Shell Programming using read Command and Command Line Arguments topic in division Essential Shell Programming of Unix

Answer»

The correct choice is (c) a file containing a series of COMMANDS

Explanation: When we have to EXECUTE a series of commands altogether, we store them in a file which is itself executed as a shell script. A shell script is basically a computer PROGRAM designed to be run by the UNIX shell.