This set of Unix Multiple Choice Questions & Answers (MCQs) focuses on “Logical Operators and Conditional Execution”.
1. Which of the following operators are used for logical execution?
a) ||
b) &&
c) %%
d) && and ||
View Answer
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:
command1 && command2 command1 || command2
2. When we use &&, the second command is executed only when first succeeds.
a) True
b) False
View Answer
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.
3. When we use ||, both the commands are executed.
a) True
b) False
View Answer
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.
4. The syntax for using && is ______________
a) cmd1 && cmd2
b) cmd1 cmd2 &&
c) cmd1 & cmd2&
d) cmd1
View Answer
Explanation: The shell provides two operators that allow conditional execution –the && and ||. The syntax for using these operators is:
cmd1 && cmd2 cmd1 || cmd2
5. To perform decision depending on the fulfillment of certain criteria, ____ is used.
a) if
b) else
c) for
d) if and else
View Answer
Explanation: 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,
If command is successful Then Execute command Else Execute command Fi
6. Every if is closed with a corresponding ____
a) else
b) fi
c) if
d) else if
View Answer
Explanation: 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.
7. To check more than two conditions, ___ is used with if-else statements.
a) while
b) for
c) elif
d) for
View Answer
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,
If command is successful Then Execute command Elif command is successful Then Execute command Else. . . Fi
8. The name of the script is stored in which special parameter?
a) $1
b) $0
c) $#
d) $*
View Answer
Explanation: There are some special parameters used by the shell. One of which is $0 which stores the name of the program.
9. Which of the following is not a special parameter used by the shell?
a) $$
b) $*
c) $?
d) $-
View Answer
Explanation:
$$ - displays PID of the current shell $* - displays the complete set of positional parameters as a single string $? - displays exit status of the last command
10. To know the exit status of a command, we can use ____
a) $$
b) $*
c) $?
d) $-
View Answer
Explanation: 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.
$ grep director.lst emp.lst >/dev/null ; echo $? 1 // success
Sanfoundry Global Education & Learning Series – Unix.
To practice all areas of Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check MCA Books
- Practice MCA MCQs
- Check Computer Science Books
- Check Unix Books
- Apply for Computer Science Internship