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.

51.

Where is the exit status of a command stored?(a) $0(b) $>(c) $1(d) $?I got this question in final exam.This key question is from Shell Programming using Various Commands in section Essential Shell Programming of Unix

Answer»

The correct choice is (d) $?

Explanation: The exit STATUS of a command is that particular value which is returned by the command to its PARENT. This value is STORED in $?.

52.

Which of the following is false?(a) here document provides standard input to any script non interactively(b) read command is used for making scripts interactive(c) $* stores the number of arguments specified(d) && and || are logical operatorsThis question was addressed to me in my homework.I would like to ask this question from Shell Programming using Various Commands in section Essential Shell Programming of Unix

Answer»

Correct choice is (c) $* STORES the number of arguments specified

For EXPLANATION: The shell uses << symbol to read data from the same file containing the SCRIPT. This is referred to as a here document. read command allows us to TAKE input from the user to make the script interactive. && and || are logical operators which allow conditional execution. $* stores the complete set of positional parameters as a single string.

53.

Which of the following option is used with a set for debugging shell scripts?(a) -a(b) -x(c) -d(d) -eThe question was posed to me in an online quiz.This question is from Shell Programming using Various Commands in portion Essential Shell Programming of Unix

Answer»

Correct choice is (B) -x

To explain I would say: As we know that set command is used for ASSIGNING values to POSITIONAL parameters, it also serves as debugging tool. For this purpose, we’ve to USE -x OPTION with it.

54.

Which of the following command doesn’t accept a filename as an argument?(a) cut(b) ls(c) paste(d) mailxI had been asked this question in my homework.Origin of the question is Shell Programming using Various Commands topic in division Essential Shell Programming of Unix

Answer»

Correct choice is (d) mailx

Best EXPLANATION: The mailx command doesn’t ACCEPT any filename as its ARGUMENT. So if we want to give input to the mailx command, we can use the here document.

55.

We can use the here document with interactive programs also.(a) True(b) FalseThe question was posed to me during an interview.Enquiry is from Shell Programming using Various Commands in division Essential Shell Programming of Unix

Answer»

The CORRECT choice is (a) True

The best explanation: MANY commands require input from the user. So we can USE the here document with interactive programs also. In this MANNER, we can instruct any script to take the input non-interactively by supplying the input using the here document. For example,

56.

____ command is the appropriate way to interrupt a program.(a) kill(b) SIGKILL(c) INT(d) trapThe question was posed to me in homework.Question is from Shell Programming using Various Commands in portion Essential Shell Programming of Unix

Answer»

Right ANSWER is (d) TRAP

For explanation I would say: Any shell script is terminated when the interrupt key is PRESSED. But this is not the appropriate way of doing so. For interrupting any program we should USE the trap command.

57.

Any command using standard input can take the input from here document.(a) True(b) FalseI had been asked this question in an interview for internship.My question comes from Shell Programming using Various Commands in section Essential Shell Programming of Unix

Answer»

Correct option is (a) True

Easiest explanation: The shell USES >> SYMBOL to read data from the same file CONTAINING the script. This is referred to as a here DOCUMENT. It ALLOWS any command (which uses standard input) to take input from it.

58.

The ____ allows us to read data from the same file containing the script.(a) >>(b)

Answer»

The CORRECT option is (b) <<

Easy explanation: It may happen that the data our program wants to read is fixed and limited. The shell uses << symbol to read data from the same file containing the script. This is REFERRED to as a here document, SIGNIFYING that the data is here rather than in a separate file.

59.

Which symbol is used with the set command for command substitution?(a) –(b) —(c) ??(d) _The question was posed to me in semester exam.This intriguing question originated from Shell Programming using Various Commands topic in section Essential Shell Programming of Unix

Answer»

Correct answer is (b) —

For EXPLANATION I would say: set statement can also be used for command substitution. There can be a PROBLEM especially when the OUTPUT of the command BEGINS with a-.It may happen that set INTERPRETS it as an option. To avoid this condition, we have to use — (double hyphen) immediately after set. For example,

60.

Which one of the following is an internal command?(a) cut(b) expr(c) set(d) IsThis question was addressed to me in an interview.My doubt is from Shell Programming using Various Commands in portion Essential Shell Programming of Unix

Answer»

The correct CHOICE is (c) set

For EXPLANATION I would say: set statement is an INTERNAL command which assigns its ARGUMENTS to POSITIONAL parameters $1, $2 and so on. While cut, Is and expr are external commands.

61.

____ statement is used for shifting arguments left.(a) set(b) shift(c) cut(d) pasteI had been asked this question during an interview.I'm obligated to ask this question of Shell Programming using Various Commands topic in portion Essential Shell Programming of Unix

Answer»

Correct answer is (B) shift

Explanation: shift statement TRANSFERS the content of a positional parameter to its IMMEDIATE lower numbered one. This PROCESS continues as many times as shift is invoked. For example, when CALLED once, $2 becomes $1 and $3 becomes $2 and so on.

62.

Which command is used by the shell for manipulating positional parameters?(a) set(b) cut(c) case(d) pasteThis question was posed to me in an online interview.The question is from Shell Programming using Various Commands in portion Essential Shell Programming of Unix

Answer»

Right choice is (a) set

The EXPLANATION: set statement is an internal command which assigns its ARGUMENTS to POSITIONAL PARAMETERS $1, $2 and so on. For EXAMPLE, the following command will assign the value 1345 to $1 and 5678 to $2,

63.

Which command is used for changing filename extensions?(a) chown(b) rename(c) basename(d) rmThis question was posed to me in exam.I want to ask this question from Shell Programming using Various Commands topic in division Essential Shell Programming of Unix

Answer»

The correct option is (c) basename

To EXPLAIN I WOULD say: basename command is used for changing the extensions of a group of FILENAMES. It EXTRACTS the “base” filename from an absolute filename. For EXAMPLE,

64.

Which one of the following is used for looping with a list?(a) while(b) until(c) case(d) forThe question was asked in an internship interview.The doubt is from Shell Programming using Various Commands topic in division Essential Shell Programming of Unix

Answer» RIGHT choice is (d) for

Easy explanation: The SHELL’s for loop differs in structure as used in C. for loop doesn’t test a condition but it uses a LIST INSTEAD. The syntax for USING for loop is:
65.

Which of the following loop statements uses do and done keyword?(a) for(b) while(c) case(d) for and whileThe question was asked during an online interview.Enquiry is from Shell Programming using Various Commands topic in section Essential Shell Programming of Unix

Answer» RIGHT answer is (d) for and while

Explanation: Like while LOOP, for also uses the KEYWORDS do and DONE, but the additional parameters used in for are variables and list.
66.

Which of the following keywords are used in while loop?(a) do(b) done(c) then(d) do and doneThe question was asked in quiz.Question is from Shell Programming using Various Commands in portion Essential Shell Programming of Unix

Answer» CORRECT ANSWER is (d) do and done

Explanation: while LOOP repeatedly PERFORMS a set of instructions until the CONTROL command returns a true exit status. The general syntax for while loop is:
67.

until loop operates with a reverse logic as used in while loop.(a) True(b) FalseThis question was posed to me in my homework.Question is taken from Shell Programming using Various Commands in portion Essential Shell Programming of Unix

Answer»

Correct option is (a) True

Easy EXPLANATION: SHELL also offers an until statement which operates with a reverse logic USED in while. With until the loop body is executed as LONG as the condition REMAINS false.

68.

Which of the following commands let us perform a set of instructions repeatedly?(a) for(b) while(c) until(d) for, while, untilThe question was asked in an interview for internship.Asked question is from Shell Programming using Various Commands in portion Essential Shell Programming of Unix

Answer»

The correct choice is (d) for, while, until

To ELABORATE: For REPEATEDLY performing a set of instructions, we have to use loops. Shell features THREE TYPES of loops —while, for and until. All of them repeat the INSTRUCTION set enclosed by certain keywords.

69.

expr is a _____ command(a) internal(b) external(c) shell(d) derivedI had been asked this question in an international level competition.Query is from Case and Expr Command topic in division Essential Shell Programming of Unix

Answer» CORRECT option is (b) EXTERNAL

The EXPLANATION is: expr command is an external command.
70.

For locating the first position of a character in a string we can use expr command.(a) True(b) FalseThis question was posed to me during an online exam.Question is from Case and Expr Command topic in section Essential Shell Programming of Unix

Answer»

Right answer is (a) True

The explanation: expr command can ALSO locate the first OCCURRENCE of character INSIDE a string. For example, to locate the POSITION of character d in the string ‘abdullah’, we have to COUNT the number of characters which are not ‘d’ ([^d]*),

71.

Which of the following pattern is used for extracting a substring using expr?(a) /( )(b) \(. .\)(c) . .\)(d) \\(I have been asked this question in quiz.My question comes from Case and Expr Command topic in chapter Essential Shell Programming of Unix

Answer»

Right OPTION is (B) \(. .\)

To elaborate: expr can extract a substring enclosed by the escaped characters \ ( and \). For example, to extract ‘03’ from the string 2003 USE the following command:

72.

Which symbol is used for finding the length of the string?(a) .(b) *(c) .*(d) .*.I got this question in final exam.The query is from Case and Expr Command topic in section Essential Shell Programming of Unix

Answer»

The CORRECT option is (C) .*

For explanation: The length of the string can be extracted using .* . This regular expression signifies to EXPR that it has to display the number of characters MATCHING the pattern i.e. the length of the ENTIRE string. For example,

73.

The string to be worked upon is placed on the left of the colon when using expr string handling function.(a) True(b) FalseI got this question in an international level competition.The above asked question is from Case and Expr Command topic in portion Essential Shell Programming of Unix

Answer»

Correct OPTION is (a) True

Explanation: For EVALUATING strings expr uses two expressions separated by a colon. The STRING to be worked upon is PLACED on the left of the colon while a REGULAR expression is placed on its right.

74.

Which of the following is performed by expr string handling’s function?(a) determine the length of string(b) extract a substring(c) locate the position of a character in a string(d) determine the length of string, extract and locate the position of the stringI have been asked this question in an interview for job.My doubt is from Case and Expr Command in section Essential Shell Programming of Unix

Answer»

Correct ANSWER is (d) DETERMINE the length of string, extract and locate the position of the string

To explain I would say: Though EXPR’s string handling features are not that elegant, bourne shell users HARDLY have any choice. For evaluating strings expr USES two expressions separated by a colon.

75.

expr can perform ____ arithmetic operations.(a) 2(b) 4(c) 5(d) 3I had been asked this question in an internship interview.This interesting question is from Case and Expr Command topic in chapter Essential Shell Programming of Unix

Answer»

The CORRECT CHOICE is (c) 5

Easiest explanation: expr command can perform four basic ARITHMETIC operations as well as the modulus function. For EXAMPLE,

76.

Which command is used for computation and string handling?(a) expr(b) case(c) if(d) readThe question was posed to me in final exam.Asked question is from Case and Expr Command topic in portion Essential Shell Programming of Unix

Answer»

Correct choice is (a) expr

The explanation: The bourne shell can CHECK whether an integer is greater than ANOTHER or not, but it doesn’t have any COMPUTING features at all. It has to RELY totally on expr command for that PURPOSE. This command performs two functions:

•Performs arithmetic operations on integers

•Manipulates strings

77.

case can also be used for matching multiple patterns.(a) True(b) FalseI had been asked this question at a job interview.The question is from Case and Expr Command in portion Essential Shell Programming of Unix

Answer»

The correct CHOICE is (a) True

To explain: CASE statement can also specify the same action for more than one pattern. Suppose, a PROGRAMMER wants to develop a logic for both Y or y (or N or n), then he/she can MAKE use of the case statement in the following MANNER:

78.

case can also use wildcards to pattern matching.(a) True(b) FalseThis question was posed to me in examination.Enquiry is from Case and Expr Command in chapter Essential Shell Programming of Unix

Answer»

Right answer is (a) True

Explanation: CASE statement has SUPERB string matching feature that uses wildcards. It uses the filename matching meta-characters *, ? and the CHARACTER class for matching STRINGS.

79.

The ___ option in case statement matches any option not matched by the previous options.(a) ^(b) $(c) *(d) //This question was addressed to me in exam.I'd like to ask this question from Case and Expr Command topic in portion Essential Shell Programming of Unix

Answer» CORRECT answer is (C) *

The EXPLANATION: The last option (*) or the default option is used for matching any option which is not matched by any of the previously specified OPTIONS. For example,
80.

case statement should have a corresponding closing esac.(a) True(b) FalseThis question was addressed to me in an international level competition.This is a very interesting question from Case and Expr Command in section Essential Shell Programming of Unix

Answer» RIGHT choice is (a) True

To explain I would SAY: Alike EVERY if statement is closed with a fi, CASE statement should also be closed with a CORRESPONDING esac. Without it, we’ll encounter an error.
81.

Every pattern in case statement in terminated with a _____(a) ;(b) :(c) ;;(d) //I have been asked this question by my college director while I was bunking the class.This interesting question is from Case and Expr Command topic in portion Essential Shell Programming of Unix

Answer»

The correct answer is (c) ;;

To elaborate: case STATEMENT MATCHES an expression for more than ONE ALTERNATIVE. Every pattern in the case statement is TERMINATED with a ;; .

82.

____ statement matches an expression for more than one alternative.(a) for(b) while(c) elif(d) caseThe question was posed to me during an interview for a job.This question is from Case and Expr Command in portion Essential Shell Programming of Unix

Answer»

Correct option is (d) case

Explanation: The case statement is the second conditional offered by the shell. This statement MATCHES an EXPRESSION for more than one ALTERNATIVE. case statements are used in menu-driven PROGRAMS. The syntax of the case statement is:

case expression in

83.

To check if two files are linked to each other, we can use -ef option.(a) True(b) FalseThis question was posed to me in semester exam.This is a very interesting question from Using test and [ ] to Evaluate Expressions in section Essential Shell Programming of Unix

Answer»

Correct choice is (a) True

Explanation: If we have two files namely FILE01 and FILE02 and we WANT to CHECK if file01 is LINKED with file02, we have to use -ef option with test. The syntax is file01 -effile02.

84.

____ option is used for checking whether a particular file is older than a specified file.(a) -ef(b) -old(c) -nt(d) -otThe question was asked in an interview for job.My question comes from Using test and [ ] to Evaluate Expressions in portion Essential Shell Programming of Unix

Answer»

Right option is (d) -ot

Easiest explanation: If we have two file namely file01 and file02 and we WANT to CHECK if file01 is older than file02, we have to USE -ot option with test. The syntax is file01 -otfile02. Similarly, to check whether file01 is newer than file02 we’ve to use -nt option. These COMMANDS work in korn and bash shell only.

85.

-d option is used for checking if the file exists and is a directory.(a) True(b) FalseThis question was addressed to me in exam.I want to ask this question from Using test and [ ] to Evaluate Expressions topic in section Essential Shell Programming of Unix

Answer»

The CORRECT choice is (a) True

Easy explanation: If we WANT to check whether the file exists and is a DIRECTORY we have to use the -d OPTION. The syntax is -d filename.

86.

To check if the file exists and is executable we have to use ___ option with test.(a) -e(b) -f(c) -x(d) -wThis question was posed to me during an interview.The question is from Using test and [ ] to Evaluate Expressions in section Essential Shell Programming of Unix

Answer»

The correct answer is (c) -x

Easiest explanation: If we want to check whether the file exists and is EXECUTABLE we have to USE the -x option. The syntax is -x FILENAME.

87.

Which of the following option is used for checking if the file is writable or not?(a) -e(b) -f(c) -n(d) -wI got this question in unit test.I'd like to ask this question from Using test and [ ] to Evaluate Expressions in portion Essential Shell Programming of Unix

Answer»

The correct OPTION is (d) -W

For EXPLANATION I would say: To check if the FILE exists and is writable we can use -w option. The syntax is -w filename.

88.

Which of the following option is used for checking if the file is readable or not?(a) -r(b) -f(c) -n(d) -zThis question was posed to me during an interview.This interesting question is from Using test and [ ] to Evaluate Expressions in portion Essential Shell Programming of Unix

Answer»

The correct choice is (a) -R

The best I can EXPLAIN: To CHECK if the file EXISTS and is readable we can use -r OPTION. The syntax is -r filename.

89.

Which option is used for checking if the file exists or not?(a) -e(b) -a(c) -n(d) -fThe question was posed to me in an interview for job.The question is from Using test and [ ] to Evaluate Expressions topic in portion Essential Shell Programming of Unix

Answer»

Right option is (a) -e

Best explanation: test can ALSO be used to test the various file ATTRIBUTES like its type (ordinary, regular or symbolic LINK). To CHECK whether the file EXISTS or not, we can use the -e option. For example,

90.

We can use a test to test various file attributes.(a) True(b) FalseThe question was posed to me by my college professor while I was bunking the class.My question is from Using test and [ ] to Evaluate Expressions topic in chapter Essential Shell Programming of Unix

Answer»

Correct answer is (a) True

Explanation: test can also be used to test the various FILE attributes LIKE its TYPE (ordinary, regular or symbolic link) or its PERMISSIONS (read, write, execute, etc).

91.

Which one of the following option is used for checking that the string is NULL string?(a) -a(b) -o(c) -z(d) -nI got this question in unit test.Origin of the question is Using test and [ ] to Evaluate Expressions in division Essential Shell Programming of Unix

Answer»

The correct choice is (c) -z

For explanation I WOULD SAY: test can be used to compare STRINGS with another set of OPERATORS. -z is used for checking if the STRING is null. For example,

92.

Which one of the following option is used for AND operation in test command?(a) -o(b) -a(c) -e(d) -anI got this question by my college director while I was bunking the class.This is a very interesting question from Using test and [ ] to Evaluate Expressions in division Essential Shell Programming of Unix

Answer»

The correct ANSWER is (b) -a

The explanation is: test also permits the CHECKING of more than ONE condition in the same LINE using -a (AND) operator. For EXAMPLE,

93.

Which one of the following option is used for checking that the string is not null?(a) -a(b) -o(c) -z(d) -nI have been asked this question in quiz.Question is from Using test and [ ] to Evaluate Expressions topic in chapter Essential Shell Programming of Unix

Answer»

The correct choice is (d) -n

For EXPLANATION I would say: TEST can be USED to compare strings with ANOTHER set of operators. -n is used for checking if the STRING is not null. For example,

94.

Which one of the following option is used for OR operation in test command?(a) -o(b) -a(c) -e(d) -anThis question was addressed to me in my homework.I'm obligated to ask this question of Using test and [ ] to Evaluate Expressions topic in chapter Essential Shell Programming of Unix

Answer»

Correct choice is (a) -o

For explanation I would say: TEST ALSO permits the CHECKING of more than one condition in the same line using -o (OR) operator. For example,

95.

It is essential to use whitespaces when we use [].(a) True(b) FalseI had been asked this question in my homework.My query is from Using test and [ ] to Evaluate Expressions in portion Essential Shell Programming of Unix

Answer»

Correct choice is (a) True

To EXPLAIN I would say: We must provide whitespaces AROUND the operators (LIKE -eq), their operands (like $x) and inside the [ and ].

96.

test and [ ] can be used for string comparison.(a) True(b) FalseI got this question in a national level competition.The query is from Using test and [ ] to Evaluate Expressions topic in chapter Essential Shell Programming of Unix

Answer»

Right option is (a) True

To elaborate: test can be used to compare strings with another set of OPERATORS (LIKE = for EQUALITY of strings and != for inequality). For example, [ ! -z$string ] negates [ -z$string ].

97.

Which of the following operator is used as a shorthand for test?(a) % %(b) [ ](c) & &(d) ( )The question was asked in semester exam.My doubt is from Using test and [ ] to Evaluate Expressions topic in division Essential Shell Programming of Unix

Answer»

Right choice is (b) [ ]

For explanation: UNIX PROVIDES a shorthand for test i.e. [ ]. We can use this PAIR of rectangular brackets enclosing the EXPRESSION. THUS the following two are equal,

98.

We can use comparison operators without a ‘-‘.(a) True(b) FalseI have been asked this question during an interview.I want to ask this question from Using test and [ ] to Evaluate Expressions in chapter Essential Shell Programming of Unix

Answer»

Correct CHOICE is (b) False

Easiest EXPLANATION: Every numerical comparison operator used by the test BEGIN a hyphen, followed by a TWO letter string and enclosed by a WHITESPACE on either side.

99.

___ implies greater than and ____ implies less than.(a) gt, le(b) gt, lt(c) ge,le(d) ge,ltI have been asked this question during a job interview.Query is from Using test and [ ] to Evaluate Expressions in portion Essential Shell Programming of Unix

Answer»

Correct choice is (B) gt, lt

To EXPLAIN: There are some COMPARISON operators which are used by test. For example,

gt implies greater than, lt implies less than, LE implies less than or equal to, ge implies greater than or equal to.

100.

Which of the following operators is used with test for comparison of numeric values?(a) -eq(b) -ne(c) -gg(d) –eq and -neThis question was addressed to me during an interview.My question comes from Using test and [ ] to Evaluate Expressions in division Essential Shell Programming of Unix

Answer»

The CORRECT choice is (d) –eq and -ne

To EXPLAIN: There are some comparison operators which are USED by test. For EXAMPLE,