Shell (Bash) Tutorial

Shell Fundamentals

Understanding the command line, Bash, and the Shell ecosystem

What is a Shell?

A Shell is a computer program which exposes an operating system's services to a human user or other program. In general, operating system shells use either a command-line interface (CLI) or graphical user interface (GUI), depending on a computer's role and particular operation.
When people say "Shell Scripting," they are usually referring to Bash (Bourne Again SHell), the standard shell for most Linux distributions and macOS.
bash
#!/bin/bash
echo "Hello, Nocturnal Codex!"

Why Choose Shell?

  1. Automation: Automate repetitive tasks, from file management to server deployments.
  2. The Glue: Connect different programs together using "Pipes."
  3. Speed: Navigating the terminal is often much faster than using a mouse and a GUI.
  4. Universal: Almost every server in the world runs a Unix-like OS where shell skills are essential.

The Shell Ecosystem

  • Bash: The industry standard. Most scripts are written in Bash.
  • Zsh: The default shell on modern macOS. Highly customizable and user-friendly.
  • Fish: A modern, "friendly" shell with auto-suggestions and colors out of the box.

The Shebang (#!)

Wait! Every shell script should start with a Shebang. It tells the operating system which interpreter to use to run the script.
bash
#!/bin/bash

Permissions

To run a script, you must first give it "Execute" permissions using the chmod command.
bash
chmod +x my_script.sh
./my_script.sh

Summary

FeatureDescription
InterpreterBash, Zsh, Sh, Dash
CommandA single program to run (e.g., ls, grep)
ScriptA file containing a series of commands
TerminalThe application that runs the shell (e.g., iTerm, Alacritty)
Best ForAutomation, SysAdmin, DevOps, Workflow optimization
LogicCommands and control flow
SafetyPowerful but dangerous; always check your paths!
ModernZsh and Fish are popular for interactive use; Bash for scripts
StandardPart of the POSIX standard
IdentityThe "Native Language" of the Linux operating system