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.

1.

Command substitution requires the command to use ________(a) standard input(b) standard output(c) standard error(d) all of the mentionedI got this question in an interview for internship.This is a very interesting question from Command Substitution and Shell Variables in division The Shell of Unix

Answer»

The correct answer is (b) STANDARD output

The best I can explain: The SHELL enables one or more command ARGUMENTS to be obtained from the standard output of another command. This feature is called command substitution and it requires the command to use the standard output (STREAM).

2.

Which of the following is not a system defined variable?(a) $PATH(b) $HOME(c) $SHELL(d) $cdThis question was posed to me in a job interview.The doubt is from Command Substitution and Shell Variables topic in section The Shell of Unix

Answer»

The correct answer is (d) $cd

For explanation: PATH is the shell variable which stores the LIST of directories that the shell searches for locating commands. HOME prints our home directory while SHELL prints the absolute pathname of our LOGIN shell. cd is a command which is used for changing directories or moving through file HIERARCHY.

3.

Which of the following is an invalid variable?(a) _user(b) us01(c) -txtfile(d) txt123The question was asked by my college professor while I was bunking the class.My enquiry is from Command Substitution and Shell Variables topic in division The Shell of Unix

Answer»

Correct option is (c) -txtfile

The explanation is: UNIX restricts some RULE for defining a VARIABLE. A variable name MUST BEGIN with either an underscore (_) or alphanumeric character followed by ONE or more alphanumeric or underscore characters.

4.

C shell uses which command for assigning values to variables?(a) =(b) set(c) unset(d) $The question was posed to me by my college professor while I was bunking the class.This interesting question is from Command Substitution and Shell Variables topic in division The Shell of Unix

Answer»

Right choice is (b) set

For explanation I would say: The C shell USES the set statement to set VARIABLES. There is a restriction that there either has to be whitespace on both sides of = or none at all. For EXAMPLE, for assigning a value to a variable named count, USE the following command:

5.

The variable assignment as x = 10 (whitespace on both sides of =) will work if we are not using C shell?(a) True(b) FalseI have been asked this question in a national level competition.This interesting question is from Command Substitution and Shell Variables in division The Shell of Unix

Answer» CORRECT choice is (b) False

Explanation: If we are using any other shell other than C shell, the assignment in the FORM x = 10 will PRODUCE an error because the shell will interpret x as a COMMAND and =,10 as its arguments.
6.

readonly command is used to protect a variable from reassignment.(a) True(b) FalseI have been asked this question in homework.The above asked question is from Command Substitution and Shell Variables topic in portion The Shell of Unix

Answer»

The CORRECT OPTION is (a) True

To elaborate: A variable can be protected from reassignment by readonly command. unset is also an INTERNAL command. For example, to PROTECT a variable x from reassignment USE the following command,

7.

Which of the following is a correct initialization of variables to null strings?(a) x=(b) x=’ ‘(c) x=” “(d) x=, x=’ ‘, x=” “The question was posed to me by my college director while I was bunking the class.I want to ask this question from Command Substitution and Shell Variables topic in chapter The Shell of Unix

Answer» CORRECT option is (d) X=, x=’ ‘, x=” “

The BEST explanation: All shell variables are initialized to NULL strings by a string. While explicit ASSIGNMENT of null strings can be performed with x=’ ‘ or x=” “ or x=
8.

A variable can be removed using _____(a) unset(b) readonly(c) del(d) bashI have been asked this question during a job interview.This question is from Command Substitution and Shell Variables in chapter The Shell of Unix

Answer»

The correct CHOICE is (a) UNSET

The EXPLANATION: A variable can be REMOVED using the unset command. unset in an internal command. For example, if we want to undefine a variable x then,

9.

Which symbol is used for assigning a value to variables?(a) $(b) &(c) =(d) @I have been asked this question in an internship interview.My question is taken from Command Substitution and Shell Variables topic in section The Shell of Unix

Answer»

Correct answer is (c) =

EXPLANATION: The SHELL supports variables that are useful both in the command line and shell SCRIPTS. These variables are called shell variables like pwd.A variable ASSIGNMENT is of the form variable=value(no SPACES around =). For example,

10.

Which symbol is used for evaluation of variables?(a) $(b) &(c) =(d) @The question was asked in an interview for job.My question is taken from Command Substitution and Shell Variables topic in portion The Shell of Unix

Answer» RIGHT CHOICE is (a) $

The explanation: The shell supports variables that are useful both in the command line and shell scripts. These variables are called shell variables like TERM and SHELL.A variable assignment is of the form variable=value(no spaces around =), but its evaluation REQUIRES the $ as a prefix to the variable name. For EXAMPLE,
11.

Which of the following shell doesn’t support the command substitution using $ recommended by POSIX?(a) Korn(b) bash(c) C(d) bourneThis question was addressed to me by my school teacher while I was bunking the class.This question is from Command Substitution and Shell Variables in chapter The Shell of Unix

Answer»

Right option is (d) bourne

Easy explanation: Whether or not we USE POSIX NOTATION for command substitution is something up to the USER. But we should make sure that we do not have to run our SHELL scripts with the Bourne shell because $(command) is not SUPPORTED by Bourne shell.

12.

POSIX recommends the use of ____ instead of archaic `command ` for command substitution.(a) |(b) #(c) %(d) $The question was asked in examination.My question is based upon Command Substitution and Shell Variables topic in division The Shell of Unix

Answer»

Right answer is (d) $

Explanation: POSIX recommends the use of the form $(command) instead of archaic `command` for command SUBSTITUTION. For example, to display the DATE USING command substitution use the FOLLOWING command:

13.

Shell enables one or more arguments to be obtained from the standard output of another command. This feature is called _________(a) command substitution(b) argument substitution(c) shell substitution(d) kornThis question was posed to me in examination.My question is based upon Command Substitution and Shell Variables topic in division The Shell of Unix

Answer»

Correct option is (a) command substitution

Explanation: APART from a pipeline, SHELL enables connecting of two commands in ANOTHER WAY. Shell enables one or more arguments to be obtained from the standard output of another command. This feature is called command substitution. For EXAMPLE, to display output like:

14.

Which of the following meta-character is used in command substitution?(a) `(b) ‘(c) “(d) >The question was posed to me in class test.This intriguing question originated from Command Substitution and Shell Variables in portion The Shell of Unix

Answer»

Correct CHOICE is (a) `

The explanation is: When SCANNING the command line, the SHELL looks for another metacharacter i.e. ` (the backquote) usually placed on the top-left of our keyboard, and it should not be CONFUSED with a single quote (‘).

15.

Command substitution is enabled in single quotes also.(a) True(b) FalseThis question was addressed to me during a job interview.The query is from Command Substitution and Shell Variables topic in portion The Shell of Unix

Answer» CORRECT option is (B) False

The BEST I can explain: Command substitution is enabled only when we use double quotes. If we use single quotes, it will not WORK. For example,
16.

Apart from its use in redirection, /dev/tty can also be used as an argument to some commands.(a) True(b) FalseI have been asked this question by my college professor while I was bunking the class.My query is from Redirection and Pipes topic in chapter The Shell of Unix

Answer»

The correct option is (a) True

To EXPLAIN I would SAY: /dev/tty can be used as an argument to some UNIX commands. Because the TERMINAL is also a file we can USE the device name /dev/tty as an argument to some commands like tee. For example,

17.

Which of the following is not true about tee command?(a) it is a feature of the shell(b) it is an external command(c) tee command duplicates its input(d) tee is an internal commandI got this question during an interview.The doubt is from Redirection and Pipes in section The Shell of Unix

Answer»

The correct choice is (a) it is a feature of the SHELL

Explanation: TEE command is not a feature of the shell. tee command HANDLES a character stream by DUPLICATING its input. It saves one copy in a file and writes the other to standard output. It is an external command.

18.

tee is an internal command.(a) True(b) FalseThe question was posed to me in an internship interview.The above asked question is from Redirection and Pipes topic in section The Shell of Unix

Answer»

The correct answer is (b) False

For explanation: tee is an EXTERNAL command and not a feature of the shell. tee command handles a character STREAM by DUPLICATING its input. It saves one copy in a file and WRITES the other to standard OUTPUT.

19.

Which command saves one copy of character stream in a file and store the other to standard output?(a) who(b) ls(c) tee(d) wcThis question was posed to me during an online interview.My question comes from Redirection and Pipes topic in section The Shell of Unix

Answer»

Correct option is (c) tee

Explanation: tee command handles a CHARACTER stream by DUPLICATING its input. It saves ONE COPY in a file and WRITES the other to standard output. For example,

20.

In a pipeline, the command on the left of | must use standard output and one on the right must use standard input.(a) True(b) FalseThis question was addressed to me by my college director while I was bunking the class.Asked question is from Redirection and Pipes in division The Shell of Unix

Answer»

Right ANSWER is (a) True

To ELABORATE: There is a restriction which is applied while using a pipeline. In a pipeline, the COMMAND on the left of | must use STANDARD output (stream)and one on the right must use standard input (stream). Otherwise, an error will be generated or the output will be erroneous.

21.

We can use the > symbol along with pipe in a command.(a) True(b) FalseThe question was asked in a national level competition.My question is taken from Redirection and Pipes topic in section The Shell of Unix

Answer»

The correct option is (a) True

To explain: There is no RESTRICTION on the number of commands we can use in a pipeline EXCEPT that we should KNOW the behavioral properties of these commands to place there. For EXAMPLE, CONSIDER this command:

22.

Which symbol is used to connect different streams?(a) |(b) >(c)

Answer» CORRECT option is (a) |

The best I can explain: The shell can connect DIFFERENT streams using a special operator called PIPE (|) and avoid CREATION of disk FILE. We can connect two commands using this operator so that one command can take the output of other as its input. For example,
23.

Which file is used for indicating terminals?(a) /dev/tty(b) /dev/null(c) terminal file(d) device fileI got this question in homework.My doubt stems from Redirection and Pipes topic in division The Shell of Unix

Answer»

Right answer is (a) /dev/tty

For explanation I WOULD say: /dev/tty is another special file which is used for REPRESENTING ONE’s terminal. Consider user1 is working on terminal /dev/pts/1 and USER 2 is working on /dev/pts/2. Then, both the users can refer to their own TERMINALS with the same filename. For example, if user 1 issues the command

24.

Which symbol is used to redirect error messages to /dev/null?(a) %(b) $(c) >(d)

Answer»

The CORRECT answer is (c) >

Best explanation: As we REDIRECT our output using > symbol to other files in simple commands, this technique can also be USED to redirect ERROR messages to /dev/null file. For example,

25.

Which of the following files are known as special files in UNIX?(a) sample.txt(b) /dev/null(c) /dev/tty(d) /dev/null and /dev/ttyThis question was addressed to me in final exam.Query is from Redirection and Pipes in division The Shell of Unix

Answer»

Correct answer is (d) /dev/null and /dev/tty

The explanation is: There are two special files named /dev/null and /dev/tty which is used in UNIX for special purposes. For example, if we want to check whether the program runs SUCCESSFULLY without seeing its output on the screen or may not want to SAVE output in a file either. For this purpose, a special file /dev/null is used. It accepts any STREAM without GROWING in size. The second file /dev/tty is the one used for indicating one’s terminal.

26.

The size of /dev/null is always zero.(a) True(b) FalseI have been asked this question during an interview.My question comes from Redirection and Pipes in section The Shell of Unix

Answer»

Right option is (a) True

To explain: UNIX has a special file that simply accepts any stream WITHOUT GROWING in size. This file is /dev/null. This file is used for redirecting error messages away from the terminal so that they don’t appear on the SCREEN. This file is pseudo-device because like other device FILES, it’s not ASSOCIATED with any physical device.

27.

We can redirect the error message to file named newfile using __________ command.(a) catfooerrorfile(b) catfoo >errorfile(c) cat errorfile>foo(d) cat foo 2>errorfileThe question was posed to me by my school principal while I was bunking the class.This interesting question is from Redirection and Pipes in division The Shell of Unix

Answer»

Right answer is (d) cat foo 2>errorfile

The best explanation: Redirecting standard error REQUIRES the 2> symbol. Suppose if foo doesn’t EXIST then an error message ‘cannot open foo’ will be generated but we can send this message to another FILE. But here > and >> cannot be used. We have to USE 2> symbol as the file descriptor number 2 represents the standard error stream.

28.

Which file descriptor is used to represent standard error stream?(a) 0(b) 1(c) 2(d) 3I got this question during an online exam.This question is from Redirection and Pipes topic in chapter The Shell of Unix

Answer» RIGHT answer is (c) 2

The best EXPLANATION: Each of the three standard files is represented by a number called as a file descriptor. A file is opened using its pathname, but subsequent read and write operations identify the file by this file descriptor. Whenever we ENTER an incorrect command or try to OPEN a non-existent file, certain diagnostic messages are displayed onto the terminal. This is the standard error stream whose DEFAULT destination is the terminal.
29.

The >> symbol is used to overwrite the existing file if it exists.(a) True(b) FalseThe question was asked during an interview for a job.Question is taken from Redirection and Pipes topic in chapter The Shell of Unix

Answer» CORRECT choice is (b) False

Easy explanation: The SHELL provides the >> symbol (right chevron used twice) to append to an EXISTING file. For example,

//Do a word count PROGRAM on sample.txt and append the output to NEWFILE as shown below.

$ wcsample.txt >> newfile
30.

Which of the following symbol(s) can be used to redirect the output to a file or another program?(a) |(b) >(c) >>(d) |, > and >>This question was posed to me by my college director while I was bunking the class.This is a very interesting question from Redirection and Pipes in section The Shell of Unix

Answer» CORRECT option is (d) |, > and >>

Explanation: All commands DISPLAYING output on the TERMINAL actually write to the standard output file as a stream of CHARACTERS and not directly to the terminal as such. The symbol > will replace the default destination (terminal) with any file by using the > operator, followed by the filename while the symbol >> is used to append to a file. | is used to give input to another program.
31.

Which symbol is used for taking input from standard input?(a) &(b) %(c) –(d) $The question was posed to me during an interview.Query is from Redirection and Pipes topic in section The Shell of Unix

Answer» CORRECT option is (c) –

For explanation: When a command TAKES input from multiple SOURCES –say a file and STANDARD input, the – symbol is used to indicate the sequence of TAKING input. For example,
32.

The command wc < sample.txt will count data from the file sample.txt.(a) True(b) FalseI have been asked this question in examination.My enquiry is from Redirection and Pipes in portion The Shell of Unix

Answer»

The correct option is (a) True

To EXPLAIN I would say: When WC is used WITHOUT any arguments it will read the DATA from the default source which is a keyboard. In the above COMMAND, redirection symbol < is present. The following steps are performed:

1. On seeing the <, the shell opens the disk file, sample.txt for reading.

2. wc performs its execution and displays the output.

33.

Which stream is used for representing error messages?(a) standard input(b) standard output(c) standard error(d) errorThis question was addressed to me by my school principal while I was bunking the class.I want to ask this question from Redirection and Pipes topic in portion The Shell of Unix

Answer»

Right OPTION is (C) standard error

The best EXPLANATION: The standard error (or stream) is used for representing error messages that emanate from the COMMAND or shell. This stream is also connected to the display as error messages are DISPLAYED on the terminal.

34.

Which stream is connected to the display?(a) standard input(b) standard output(c) standard error(d) errorThe question was asked in an interview.This question is from Redirection and Pipes topic in chapter The Shell of Unix

Answer»

Right option is (b) STANDARD output

Easy explanation: Standard output is the file (or STREAM)which is used for representing output, and is connected to the display. Each COMMAND which uses the display for its output will find this file always OPEN and available. The file will be automatically closed after the command has completed its EXECUTION.

35.

How many files are used for representing different standard streams?(a) 1(b) 2(c) 4(d) 3This question was addressed to me in an internship interview.I would like to ask this question from Redirection and Pipes in division The Shell of Unix

Answer» CORRECT ANSWER is (d) 3

To explain I would say: The shell associates three files with the terminal –two for display and one for the keyboard. These SPECIAL files are actually streams of CHARACTERS which MANY commands see as input and output. Each stream is associated with a default device –which is terminal. These three files are:

•Standard Input

•Standard output

•Standard error
36.

Redirection is a process of switching of the standard stream of data.(a) True(b) FalseI got this question in final exam.Query is from Redirection and Pipes topic in section The Shell of Unix

Answer»

Correct answer is (a) True

Explanation: Redirection is a process in which switching of the standard stream of data is PERFORMED so that it comes from a SOURCE other than its DEFAULT source or so that it goes to some destination other than its default destination.

37.

Which of the following command will remove the file named * ?(a) rm *(b) rm ‘*’(c) rm \*(d) rm ‘*’ and rm \*I got this question at a job interview.This interesting question is from Pattern Matching, Escaping and Quoting in division The Shell of Unix

Answer»

Right CHOICE is (d) rm ‘*’ and rm \*

The explanation: To suppress the nature of wildcard * we can use either escaping or quoting. The \ symbol will suppress the feature of wildcard and will remove the file NAMED *. SIMILARLY using quoting we can TURN off the meaning of the META character.

38.

Double quotes are more permissive than single quotes and allow the evaluation of the $ and ` itself.(a) True(b) FalseI have been asked this question in homework.Query is from Pattern Matching, Escaping and Quoting in division The Shell of Unix

Answer»

The correct answer is (a) True

The best explanation: When a command ARGUMENT is enclosed in single quotes, the MEANING of all enclosed special characters is turned off. But when we enclose the same in double quotes, we cannot PROTECT the $ and ` (BACKQUOTE). For EXAMPLE,

39.

For escaping the newline character we can use ____(a) /(b) \(c) ?(d) \nI got this question at a job interview.Origin of the question is Pattern Matching, Escaping and Quoting in portion The Shell of Unix

Answer»

Correct answer is (b) \

The best I can explain: The newline character is also special, it marks the end of the COMMAND line. Some command lines that uses several arguments can be long ENOUGH to OVERFLOW to the next line. To split the WRAPPED line into two lines, MAKE sure you input a \ before pressing [Enter].

40.

We can escape the \ itself using escaping.(a) True(b) FalseThis question was addressed to me in my homework.Question is from Pattern Matching, Escaping and Quoting in portion The Shell of Unix

Answer»

Right ANSWER is (a) True

The explanation is: SOMETIMES we may need to INTERPRET the \ itself literally. To do so we need another \ before it. For example,

41.

To remove the file named my document.txt, which one of the following commands will be used?(a) rm my\ document.txt(b) rm my document.txt(c) rm *(d) rm my_document.txtI got this question in an interview for job.I would like to ask this question from Pattern Matching, Escaping and Quoting topic in division The Shell of Unix

Answer»

The correct answer is (a) RM my\ document.txt

For explanation: APART from metacharacters, there are other characters that are special LIKE the space CHARACTER. The shell uses it to delimit COMMAND line arguments. So to remove the file my document.txt we can use escaping. The backslash will make the shell to ignore the space. Hence file will be removed easily.

42.

Providing a backslash (\) before the wild card to remove its special meaning is called _____(a) escaping(b) quoting(c) listing(d) pattern matchingI had been asked this question in an online quiz.My doubt stems from Pattern Matching, Escaping and Quoting in portion The Shell of Unix

Answer»

Correct option is (a) escaping

Explanation: We KNOW that SHELL uses some special characters to match filenames or perform other search and replace operations. But if the filename itself contains those special characters, then it could be a great nuisance. For DEALING with such files we use escaping and quoting.

Escaping means providing a backslash (\) before the wild card so that its special meaning could be removed. For EXAMPLE, if we want to remove a file named chap*, then using the command rm chap* will DELETE all the file beginning with a prefix ’chap’. In this situation, we can use the following command,

43.

Enclosing the wild card or the entire pattern within quotes is called ___(a) escaping(b) quoting(c) listing(d) pattern matchingI got this question in semester exam.This interesting question is from Pattern Matching, Escaping and Quoting topic in division The Shell of Unix

Answer» CORRECT option is (b) QUOTING

The explanation is: There is another way to turn off the meaning of the metacharacter. When a command argument is ENCLOSED in quotes, the meaning of all special characters is turned off. This METHOD is called quoting. For EXAMPLE,
44.

The command cd * will work.(a) True(b) FalseThe question was posed to me during a job interview.I need to ask this question from Pattern Matching, Escaping and Quoting topic in chapter The Shell of Unix

Answer»

Right option is (a) True

The explanation is: As we know that CD command is used for changing directories, the command cd * will WORK only when there is only one file in the CURRENT directory and that file should ALSO be a directory. Otherwise, this command is invalid.

45.

Which of the following shell doesn’t support ! symbol for negating the character class?(a) bash(b) bash(c) POSIX(d) CI have been asked this question in a job interview.My query is from Pattern Matching, Escaping and Quoting topic in division The Shell of Unix

Answer» CORRECT OPTION is (d) C

The explanation is: The ! SYMBOL cannot be USED to negate a character class in a C shell. In fact, C shell doesn’t provide any MECHANISM for doing so.
46.

* and ? cannot match ____(a) /(b) $(c) .(d) / and .The question was asked during an interview.This intriguing question originated from Pattern Matching, Escaping and Quoting topic in section The Shell of Unix

Answer»

Correct answer is (d) / and .

The best I can explain: There are two THINGS which * and ? cannot match. First is, they cannot match filenames STARTING with a DOT (.). Second is, they cannot match / in the pathname. For example, we cannot use cd/usr?localto SWITCH to /usr/local. It will generate an error.

47.

Which of the following symbol is used for negating the character class?(a) .(b) *(c) !(d) %I had been asked this question in a job interview.This key question is from Pattern Matching, Escaping and Quoting in chapter The Shell of Unix

Answer»

Right ANSWER is (c) !

Explanation: We can use the ! as the FIRST symbol for NEGATING the CHARACTER CLASS. For example,

48.

Which of the following files will not be deleted using “rm chap??” ?(a) chap01(b) chap02(c) chaptd(d) chactdThis question was addressed to me in an online quiz.My query is from Pattern Matching, Escaping and Quoting topic in section The Shell of Unix

Answer» RIGHT option is (d) chactd

The explanation: Since ? is USED to match a SINGLE character, ?? can match two characters. So the above command will remove all FILES with a filename starting with a prefix ‘CHAP’, followed by any two characters.
49.

Which of the following command will list all the hidden filenames in our directory having at least three characters after the dot (.)?(a) ls(b) ls -a(c) ls.???*(d) ls *This question was posed to me during an interview.I'd like to ask this question from Pattern Matching, Escaping and Quoting topic in portion The Shell of Unix

Answer»

Correct CHOICE is (C) ls.???*

Best explanation: The * doesn’t MATCH all files beginning with a (.) dot. So if we NEED to lists all the HIDDEN filenames in our directory having at least three characters after the dot (.) we can use the following command,

50.

Which of the following is not a wild-card?(a) *(b) ?(c) $(d) %The question was posed to me during an online interview.This interesting question is from Pattern Matching, Escaping and Quoting topic in division The Shell of Unix

Answer»

Right answer is (c) $

The explanation: The ‘$’ sign REPRESENTS the shell PROMPT while all the other CHARACTERS belong to a category of shell wildcards.