GSEC practice question 5 of 35

You work as a Network Administrator for McNeil Inc. The company has a Linux-based network. David, a Sales Manager, wants to know the name of the shell that he is currently using. Which of the following commands will he use to accomplish the task?

Full set: 383 questions

Domain Linux: Security and Administration

Answer options
A: mv $shell
B: echo $shell Correct answer
C: rm $shell
D: ls $shell
Correct Answer:
B. echo $shell
Explanation

In Unix-like operating systems, including Linux, environment variables store information about the shell session. The $SHELL environment variable specifically holds the path to the user's default login shell (e.g., /bin/bash, /bin/zsh). The echo command is a shell built-in that prints its arguments to the standard output. Therefore, executing echo $SHELL (or $shell, assuming a common typo in the question, as environment variables are case-sensitive and typically uppercase) retrieves the value of this variable and displays it on the screen, directly answering the user's question about which shell they are using.

Why Incorrect

A. mv $shell: This command is used to move or rename files. It would incorrectly attempt to move the shell's executable file.
C. rm $shell: This is the remove command. It would dangerously attempt to delete the shell's executable file, not display its name.
D. ls $shell: This command lists file attributes. It would show details about the shell executable file, not simply print its name as requested. ---

References

1. MIT OpenCourseWare. (2020). The Missing Semester of Your CS Education, Lecture 2: Shell Tools and Scripting. Massachusetts Institute of Technology. Retrieved from https://missing.csail.mit.edu/2020/shell-tools/. In the "Shell Variables" section, it states, "To see the value of a variable, you can use the echo command... For example, the $SHELL variable has the path of the shell program itself."

2. GNU Bash Reference Manual. (2022). 5.2 Bash Variables. Free Software Foundation. Retrieved from https://www.gnu.org/software/bash/manual/htmlnode/Bash-Variables.html. The documentation lists SHELL as a variable to which "Bash assigns... the full pathname of the current user’s login shell." The manual also documents echo as the standard command for displaying values.

3. Sobell, M. G. (2012). A Practical Guide to Linux Commands, Editors, and Shell Programming. Prentice Hall. In Chapter 4, "The Bourne Again Shell," the text explains shell and environment variables, explicitly mentioning that echo $SHELL is used to display the user's login shell. (Specific reference: Chapter 4, Section: "Standard Shell Variables").

Scroll to Top