跳到主要内容

Shell Basic

I. Basic 💡

1. Brief Introduction 💬

The shell is a command-line interpreter that acts as an interface between users and the operating system kernel. It takes commands entered by the user, parses and executes them, and then returns the results.

Systems administrators can make their jobs much easier by using shell scripts to automate complex, repetitive tasks.

In any case, you can see which shell you’re using by typing: echo $SHELL

shell
信息

The shell operates in two main modes:

  • Interactive Mode: Users enter commands directly in the command line and get immediate feedback.
  • Script Mode: A series of commands are written into a text file (a shell script) and executed together.

2. Shell Categories 🗂️

Linux systems provide several types of shell command interpreters, such as sh, zsh, and bash. By default, bash is generally used as the default interpreter.

ShellInteractive FeaturesScript WritingCommon ScenariosMain Advantages
shMinimalStandardSystem scripts, strong compatibilityLightweight, high POSIX compatibility
bashRichPowerfulDefault Linux Shell, general scriptingComprehensive functionality, widely supported
zshVery richStrongPreferred interactive shell for developersHighly customizable, rich plugins
kshModerateStrongCommercial systems, compatibility scriptsPowerful syntax, comprehensive features
csh/tcshRichWeakUnix-like systems, some developersC-like syntax, built-in completion features

3. Shell Scripts 📝

A shell script is a text file composed of shell commands, written following specific syntax. These scripts (with execution permissions enabled) do not require compilation to run but are directly interpreted and executed by the shell interpreter.

Shell scripts can generally be divided into two categories:

  • System-Invoked Shell Scripts: These are scripts automatically called by the system. For example, ~/.bashrc is a user-specific configuration file that is automatically invoked during login and whenever a terminal is opened.
  • User-Created and Invoked Shell Scripts: These scripts are actively created and called by users.

In summary, shell scripts are essential tools for system administrators and developers to enhance efficiency.