July 21, 2026
Linux Shells: Terminal Interfaces, Shell Environments, and Automation
Introduction
By Jonathan Sanfer
8 min read
Introduction
Welcome to my walkthrough of the Linux Shells room! This room serves as the final step within the Command Line module of TryHackMe's Cyber Security 101 pathway.
In my previous article, Windows PowerShell, we stepped away from flat command prompts to explore object-oriented automation, pipeline filtering, and remote administration tools across Windows environments. Now, we are shifting back to Unix architecture to master how Linux handles terminal environments, shell interpreters, and task automation.
In this room, Linux Shells, we explore how shells operate as the bridge between user input and the operating system kernel. This walkthrough serves as a comprehensive guide to understanding command-line interaction mechanics, comparing common Linux shells like Bash, Fish, and Zsh, and building structured Bash scripts to automate administrative tasks.
Catch up on my previous article Windows PowerShell by clicking the banner below.
What we will cover
- Interacting with the Linux Command Line Interface (CLI) using fundamental file navigation utilities
- Comparing core capabilities, syntax features, and default configurations across Bash, Fish, and Zsh
- Constructing executable Bash scripts incorporating variables, control loops, conditional logic, and inline documentation
- Auditing and configuring log-parsing automation scripts directly on a live target machine
Room Information
Before we dive into the tasks, here is a quick overview of the room details.
- Room Name: Linux Shells
- Path: Cyber Security 101
- Module: Command Line
- Topic: Command Line / Linux Shells
- Difficulty: Easy
- Room Link: TryHackMe — Linux Shells
Task 1: Introduction to Linux Shells
Operating systems rely on user interfaces to accept commands and manage system resources. While modern desktop environments use Graphical User Interfaces (GUIs) for visual convenience, system administrators and security analysts rely on Command Line Interfaces (CLIs) for direct interaction. Operating through a terminal provides finer execution control, lower overhead, and direct access to system utilities.
A shell acts as the intermediate layer between the user and the operating system kernel. When a user inputs a text string into a terminal, the shell parses the string, translates it into instructions the operating system can execute, and returns the resulting output to the display buffer.
Learning Objectives
- Understand the role of the shell within Unix-based operating systems.
- Execute basic CLI file manipulation and navigation commands.
- Compare feature sets across common Linux shells.
- Construct and execute functional shell scripts.
Questions and Answers
Who is the facilitator between the user and the OS?
Answer:
ShellShellTask 2: How To Interact With a Shell?
When accessing a Linux system via the command line — whether locally through a terminal emulator or remotely via SSH — you are placed directly into an interactive shell session ready to accept commands.
Across the vast majority of Linux distributions (such as Ubuntu, Debian, and Fedora), Bash (Bourne Again Shell) serves as the default shell environment. Designed as an enhanced, open-source replacement for the original Unix Bourne shell (sh), Bash acts as the standard command language interpreter across modern Linux ecosystems. While specific distributions or customized desktop setups may occasionally default to alternative shells like Zsh or Dash, Bash remains the undisputed baseline shell you will encounter across servers, cloud instances, and security environments.
Interacting with a Linux environment through the command line requires familiarity with core navigation tools. When opening a terminal session, the shell displays a prompt indicating the current user context and working directory.
Basic directory operations rely on utilities like pwd (Print Working Directory) to verify location pathways, cd (Change Directory) to navigate the file system tree, and ls (List) to inspect folder contents. File analysis is performed using utilities such as cat (Concatenate) to stream file contents to stdout, and grep (Global Regular Expression Print) to search through text files for matching string patterns or regular expressions.
Questions and Answers
What is the default shell in most Linux distributions?
Answer:
BashBashWhich command utility is used to list down the contents of a directory?
Answer:
lslsWhich command utility can help you search for anything in a file?
Answer:
grepgrepTask 3: Types of Linux Shells
Operating systems accommodate a variety of shell environments, each engineered with unique feature sets, syntax rules, and interactive capabilities. In Linux, installed shells are cataloged within the /etc/shells system configuration file, while your active session's shell environment is stored in the $SHELL environment variable. Users can easily inspect installed shells using cat /etc/shells, switch to a different shell in real time simply by typing its executable name (such as zsh), or permanently update their default login shell using chsh -s /usr/bin/zsh.
Among the most common environments, the Bourne Again Shell (Bash) stands as the traditional default across most Linux distributions. Built as a feature-rich upgrade to older shells like sh, ksh, and csh, Bash includes robust command logging via a command history file. Running the history command displays all previously executed commands from your current session, allowing operators to review or re-run prior actions using arrow keys. However, as a classic and standardized shell, Bash lacks modern interactive conveniences like built-in auto spell correction for typed commands.
To address user interface limitations, alternative modern shells focus on interactivity and visual feedback. The Friendly Interactive Shell (Fish) prioritizes beginner-friendly usability, featuring built-in auto spell correction, command auto-suggestions, and syntax highlighting right out of the box to color-code command syntax and highlight typing errors in real time. Meanwhile, the Z Shell (Zsh) serves as a powerful hybrid environment combining Bash's extensive scripting framework with advanced tab completion and heavy plugin customization capabilities via frameworks like Oh My Zsh.
Questions and Answers
Which shell comes with syntax highlighting as an out-of-the-box feature?
Answer:
FishFishWhich shell does not have auto spell correction?
Answer:
BashBashWhich command displays all the previously executed commands of the current session?
Answer:
historyhistoryTask 4: Shell Scripting and Components
When administrative operations require running the same sequence of terminal commands repeatedly, executing them manually line by line becomes inefficient. Shell scripting solves this by consolidating multiple commands into a single, reusable text file (typically saved with a .sh file extension). Running this single script instructs the shell to execute every bundled command sequentially, allowing system administrators and security analysts to automate routine tasks and maintain consistent execution environments across systems.
Every standard Bash script begins on its very first line with a shebang, written explicitly as #!/bin/bash. The shebang serves as an absolute path indicator telling the operating system kernel which binary interpreter to invoke when parsing the file's code. Once the script file is saved (using a text editor like nano), it cannot be executed immediately by default. Linux enforces strict file security controls, meaning execution permissions must be granted to the file first by running chmod +x first_script.sh. After applying execution rights, launching the script requires prefixing its name with ./ (e.g., ./first_script.sh), which explicitly instructs the shell to run the executable located within the active working directory rather than searching through the system's global $PATH environment variables.
Building an effective script relies on several foundational logic components. Data storage is handled through variables, which assign values to named placeholders (such as name="Stewart" ) and recall them using a leading dollar sign ($name). To handle repetitive or iterative tasks without duplicating code blocks, scripts utilize loops (such as for or while loops) to cycle through datasets or numerical ranges automatically. Logical decision-making is controlled via conditional statements (if, elif, else, fi), which evaluate specific criteria — like checking whether an entered username matches an authorized string — and execute specific branches of code accordingly. Finally, non-executable comments prefixed with a # symbol allow developers to embed clear documentation directly alongside their logic without affecting script execution.
Questions and Answers
What is the shebang used in a Bash script?
Answer:
#!/bin/bash#!/bin/bashWhich command gives executable permissions to a script?
Answer:
chmod +xchmod +xWhich scripting functionality helps us configure iterative tasks?
Answer:
loopsloopsTask 5: The Locker Script
Putting variables, control loops, and conditional statements into practice allows developers to build functional, interactive applications such as user authentication prompts. To illustrate how these core building blocks operate together in a single program, consider a bank locker verification script designed to validate a customer before grant access to a secure vault.
When executed, the script initializes three empty variables username, companyname, and pinto store the upcoming user input. Next, a for loop running through three iterations (for i in {1..3}) controls the input flow. Inside the loop, conditional statements evaluate the current iteration counter ($i): the first pass prompts for and reads the username, the second pass collects the company name, and the final pass prompts for the numeric PIN code.
Once all three parameters are collected, a final conditional block uses the logical AND (&&) operator to verify every input simultaneously against the stored credentials. To pass the authentication gate successfully and receive the success message ("Authentication Successful. You can now access your locker, John"), the user must match all three stored values: the username John, the company name Tryhackme, and the correct numeric PIN 7385. If any single parameter fails to match during evaluation, the script immediately branches to the default fallback condition and prints an "Authentication Denied!!" message.
Questions and Answers
What would be the correct PIN to authenticate in the locker script?
Answer:
73857385Task 6: Practical Exercise
Applying scripting concepts to real-world scenarios often involves customizing existing administrative scripts to fit specific operational requirements. In this practical challenge, we examine how to configure and execute an automated log-searching script on our target Linux environment.
Guided Walkthrough: Log Parsing Script Configuration
In this practical exercise, we analyze and complete an administrative log-parsing Bash script named flag_hunt.sh located inside the /home/user directory. The goal of the script is to iterate through log files within a specified directory to locate a specific search keyword.
Because system logs reside in protected system directories such as /var/log, attempting to read them as an unprivileged user will result in permission errors. Therefore, we first elevate our privileges to the root account by executing sudo su and supplying the account password user@Tryhackme when prompted. Once elevated to root inside /home/user, inspecting flag_hunt.sh using cat reveals three unconfigured variable placeholders indicated by empty quotes: directory=" ", flag=" ", and the loop array parameter " "/*.log.
To complete the script, we open flag_hunt.sh using the nano text editor and fill in the missing variable parameters across the file. We update the directory definition to directory="/var/log" so the script targets system log locations, set the flag definition to flag="thm-flag01-script" to define our target search string, and modify the loop declaration to for file in "$directory"/*.log; do so the for loop dynamically iterates over every log file in the targeted directory.
After saving the changes and exiting nano, we launch the script using ./flag_hunt.sh. The script iterates through /var/log and reports that the flag was discovered inside authentication.log. Running cat /var/log/authentication.log streams the file contents to stdout, revealing both the flag string and the hidden phrase: "the cat is sleeping under the table".
Questions and Answers
Which file has the keyword?
Answer:
authentication.logauthentication.logWhere is the cat sleeping?
Answer:
under the tableunder the tableSummary & Key Takeaways
This room provided a fundamental overview of Linux shell environments, command-line interaction techniques, shell comparisons, and structured Bash scripting constructs.
Key lessons:
- Shells act as the core interface between terminal input and kernel processing.
- Bash, Fish, and Zsh offer distinct trade-offs between standardization, interactive usability, and plugin support.
- Shell scripts combine variables, conditional loops, and shebang execution pointers to deliver re-usable automation routines.