Skip to content

Shell

A shell is a program that provides an interface between a user and an operating system (OS) kernel.

Shell Architecture

The fundamental architecture on which the hypothetical Shell is based isn’t complex. The basic architecture is pretty similar to a pipeline, where input is analyzed and parsed, symbols are expanded. It uses a variety of methods such as brace, tilde, variable and parameter expansion and substitution, and filename generation. Then, commands are executed using shell built-in commands, or external commands.

  • The Bourne Shell (sh)
  • The C Shell (csh)
  • The Korn Shell (ksh)
  • The GNU Bourne-Again Shell (bash)
ShellPathDefault Prompt(non-root user)Default Prompt(root user)
The Bourne Shell (sh)/bin/sh and /sbin/sh$#
The C Shell (csh)/bin/csh%#
The Korn Shell (ksh)/bin/ksh$#
The GNU Bourne-Again Shell (Bash)/bin/bashbash-x.xx$bash-x.xx#
  • When: You log in via a main login screen or SSH (username/password required).
  • Files it reads: /etc/profile, ~/.bash_profile.
  • Daily Use: Best for settings that should apply globally to your account.
  • When: You are already logged in and just open a new Terminal window/tab.
  • Files it reads: ~/.bashrc.
  • Daily Use: This is where you put your Aliases (shortcuts). For example, you can tell the computer that every time you type update, it should actually run a long string of complex update commands.

Shell Auto-completion (The “Tab” Trick)

Section titled “Shell Auto-completion (The “Tab” Trick)”

This is the most important tool for your daily life to save time and prevent typos.

  • The Action: Type the first few letters of a command or folder path and press the Tab key.
  • The Result: The shell fills in the rest automatically.
  • Pro Tip: Press Tab twice to see a list of all possible files or commands that match what you’ve typed so far.

Formatting Rules • No Spaces: KEY=value (Correct) vs KEY = value (Incorrect). • Case Sensitive: NAME is different from name. • Convention: Use UPPER_CASE for environment variables. • Multiple Values: Separated by a colon (:), e.g., PATH=/bin:/usr/bin.

Common Environment Variables (Daily Life) These variables tell your apps how to behave without you having to configure them every time. • PATH: The most critical variable. It’s a list of folders the system searches to find the commands you type. If a command “isn’t found,” your PATH is usually missing a folder. • HOME: Tells apps where your personal files are (e.g., /home/username). • USER: Stores your current login name. • EDITOR: Tells the system which text editor you prefer (like nano or vim) when an app needs you to type something. • SHELL: Shows which shell you are currently using (e.g., /bin/bash).

Terminal window
echo $PATH
/home/pavan_bandaru/.local/bin:/home/pavan_bandaru/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin
echo $USER
pavan_bandaru
echo $SHELL
/bin/bash

While powerful, the shell has limits. Avoid it for:

  • Speed-Critical Tasks: Use C++ or Rust for heavy math, sorting, or hashing, recursion etc…
  • Complex Data: If you need linked lists, trees, or 3D graphics, use Python or Java.
  • Security/Privacy: Shell scripts are “open source” by nature—anyone who can run the script can read your code.
  • Mission-Critical Apps: Use languages with “type-checking” to prevent crashes in vital business software.