5.9. Shell

5.9.1. Introduction

Shell is a special program that is a bridge for users to use Linux. Shell is both a command and a programming language.

Linux contains a variety of shells, the common ones are:

  • Bourne Shell (Bourne development at ATT, named sh)

  • Bourne Again Shell (/bin/bash)

  • C Shell (developed by Bill Joy, named csh)

  • K Shell (developed by David G.koun of ATT, named ksh)

  • Z Shell (developed by Paul Falstad, named zsh)

5.9.2. Metacharacters

The shell generally has a series of special characters, which are used to achieve certain effects. Such characters are called meta characters (Meta), and the meta characters supported by different shells may be different.

Common metacharacters are as follows:

  • IFS Consists of one of <space> or <tab> or <enter>

  • CR Produced by <enter>.

  • = set variable

  • $ Substitute as variable or operation

  • > redirect stdout

  • >> append to file

  • < redirect stdin

  • | command pipeline

  • & Execute commands in the background

  • ; Execute the next command after the previous command ends

  • && Execute the next command after the previous command is executed without error

  • || Execute the next command after the execution of the previous command reports an error

  • ' Commands enclosed in single quotes retain their original values

  • " Commands enclosed in double quotes allow variable substitution

  • `` ` `` The content within the backticks will be executed as a command and replaced

  • () Execute a command in a subshell

  • {} Execute a command in the current shell

  • ~ the current user’s home directory

  • !number Execute historical commands, such as !1

5.9.3. Wildcards

In addition to metacharacters, wildcards are also a special character in the shell. When the shell encounters a wildcard in a parameter, the shell will use it as a path or filename to search for possible matches on disk: if a matching match exists, it will be replaced, otherwise the wildcard will be treated as a normal character directly transfer.

Common wildcards are as follows:

  • * matches zero or more characters

  • ? matches any character

  • [list] matches any character in list

  • [!list] matches any character except list

  • [a-c] matches any character in ac

  • {string1,string2,...} match the string respectively