Unix Shell Variables MCQs
Shell Variables MCQs : This section focuses on "Variable" in Shell Progamming in Unix. These Multiple Choice Questions (MCQ) should be practiced to improve the unix skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.
1. The name of a variable can contain ________.
A. numbers
B. letters
C. underscore character
D. All of the above
View Answer
Ans : D
Explanation: The name of a variable can contain only letters (a to z or A to Z), numbers ( 0 to 9) or the underscore character ( _).
2. Unix shell variables will have their names in _____.
A. Uppercase
B. Lowercase
C. First character Uppercase and all other character Lowercase
D. First character Lowercase and all other character Uppercase
View Answer
Ans : A
Explanation: Unix shell variables will have their names in UPPERCASE.
3. Whch of the following is invalid variable names?
A. VAR_1
B. _ALI
C. VAR1
D. VAR_A!
View Answer
Ans : D
Explanation: VAR_A! is invalid variable names.
4. Shell variables are of ____ types.
A. 3
B. 4
C. 2
D. 5
View Answer
Ans : C
Explanation: Shell variables are of two types : local and environment.
5. Which of the following command is used to display the environment variables only?
A. sh
B. set
C. env
D. var
View Answer
Ans : C
Explanation: env command is used to display environment variables only in the current shell.
6. How many prompt shell has?
A. 4
B. 2
C. 3
D. 5
View Answer
Ans : B
Explanation: The shell has two prompts (PS1 and PS2).
7. Which keyword is used to remove the variable?
A. remove
B. readonly
C. unset
D. delete
View Answer
Ans : C
Explanation: Unsetting or deleting a variable directs the shell to remove the variable from the list of variables that it tracks.
8. We cannot use the unset command to unset variables that are marked ____________.
A. read
B. write
C. readonly
D. writeonly
View Answer
Ans : C
Explanation: We cannot use the unset command to unset variables that are marked readonly.
9. Which one of the following is not an environment variable?
A. env
B. Path
C. Home
D. User
View Answer
Ans : A
Explanation: env is an external command which runs in a child process and it lists only environment variables which are inherited from its parent, the shell.
10. $# is used to show?
A. The number of arguments supplied to a script.
B. The filename of the current script.
C. The exit status of the last command executed.
D. The process number of the last background command
View Answer
Ans : A
Explanation: $# : The number of arguments supplied to a script.
Discussion