Introduction to LinuxShell

Source: Internet
Author: User
Tags add numbers
Article title: LinuxShell introduction. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
   What is Shell?
Shell is a program with special functions. it is an interface between the user and the core program (kernel) of the UNIX/Linux operating system. Why do we say shell is an intermediary between the core program of the system and the user? Readers who have read the introduction to the operating system know that the operating system is a manager and distributor of system resources. when you have requirements, you must submit them to the system. from the operating system perspective, it must also prevent system damage caused by incorrect operations? As we all know, commands on a computer can be converted into binary code through command or program. what about commands? In fact, shell is also a program that reads commands from the input device, converts them into mechanical codes that computers can understand, and then executes them.
Various operating systems have their own shells. for example, in DOS, its shell is command.com? N. For example, different command interpreter programs such as NDOS, 4DOS, and DRDOS in DOS can replace the standard command.com, except for the Bourne shell (/bin/sh) in UNIX) C shell (/bin/csh), Korn shell (/bin/ksh), Bourne again shell (/bin/bash), Tenex C shell (tcsh )... And other shells. In UNIX/Linux, the shell is independent of the core program, making it like an ordinary application, you can modify, update, or add new features without affecting the operating system.
  
   Shell activation
When the system starts, the core program is loaded with memory to manage the system until the system is closed. It establishes and controls processing programs, manages memory, file systems, communications, and so on. Other programs, including shell programs, are stored on disks. Core programs load them into memory, execute them, and clean up the system after they are aborted. Shell is a utility that starts when you check in. By interpreting commands entered by users (by command columns or command files), Shell provides the ability for users to communicate with core programs.
When you sign in (login), an interactive shell starts and prompts you to enter the command. After you type a command, it is followed by shell's work. it will:
1. syntax analysis command column
2. wildcards, redirection, pipeline, and job control)
3. search for and execute commands
When you first learn UNIX/Linux systems, most of your time is spent executing commands under the prompt.
If you often enter a group of commands in the same form, you may want to automatically execute those tasks. In this way, you can put some commands into a file (called a command file or script) and then execute this file. A shell command file is like a batch under DOS? N (such as Autoexec. bat): it stores a series of UNIX commands into a file and then executes the file. Mature command files also support control structures of several modern programming languages, such as conditional judgment, loops, file testing, and transfer parameters. To write a command file, you must not only learn the structure and skills of program design, but also have a deep understanding of UNIX/Linux utilities and how they work. Some utilities are very powerful (such as grep, sed, and awk) and are often used in command files to manipulate command output and files. After you become familiar with those tools and program design structures, you can start to write command files. When the command is executed by the command file, you have used shell as the program language.
  
   Let's talk about Shell's life
First, it is important that the standard UNIX shell is V7 (AT&T's seventh edition) UNIX, which was proposed at the end of 1979 and named after its creator Stephen Bourne. The Bourne shell is designed based on the language Algol and is mainly used for automated system management. While Bourne shell is popular for simplicity and speed, it lacks many conversational usage features, such as history, alias, and work control.
C shell was developed in the late 1970s s at the University of California, berkelai, and is released in part of 2BSD UNIX. This shell is mainly written by Bill Joy and provides some additional features that are invisible to the standard Bourne shell. C shell is based on the C program language and is used to share similar syntaxes when the program language is used. It also provides improvements in interactive application, such as command column history, alias, and work control. Because C shell is designed on a large machine and some additional functions are added, C shell runs slowly on a small machine, even on large machines, it seems slower than the Bourne shell.
With the Bourne shell and C shell, UNIX users have a choice and it is better to argue that shell. AT&T's David Korn invented the Korn shell in the middle of 1980s. it was released in 1986 and became part of the official SVR4 UNIX in 1988. The Korn shell is actually a superset of the Bourne shell. it can be executed not only on UNIX systems, but also on OS/2, VMS, and DOS. It provides upward compatibility with the Bourne shell, and adds many popular features on the C shell, increasing the speed and efficiency. The Korn shell has undergone many revisions. to find the version you are using, press Ctrl-v under the ksh symbol.
  
   Three main shells and their separation
In most UNIX systems, the three well-known and widely supported shells are Bourne shell (AT&T shell, BASH in Linux) and C shell (Berkeley shell, TCSH in Linux) and Korn shell (the superset of the Bourne shell ). The three shells in the interactive mode behave similarly, but as a command file language, the syntax and execution efficiency are somewhat different.
The Bourne shell is a standard UNIX shell, which was often used as a management system. Most of the system management command files, such as rc start, stop, and shutdown, are the Bourne shell command files, and in single user mode) it is often used by system administrators when checked in as root. The Bourne shell is developed by AT&T and is famous for its simplicity and speed. The default value of the Bourne shell prompt symbol is $.
C shell is developed by Berkeley and has added some new features, such as command history and alias (alias), built-in arithmetic, filename completion, and job control ). For users who often execute shell in conversation mode, they prefer to use C shell, but for system managers, they prefer to use the Bourne shell as the command file because of the Bourne shell command? N is simpler and faster than the C shell command file. The default value of the C shell prompt symbol is %.
Korn shell is a superset of the Bourne shell, developed by David Korn of AT&T. It adds some features and is more advanced than C shell. Features of the Korn shell include editable history, alias, function, regular expression wildcard, built-in arithmetic, job control, and coprocessing) and special debugging functions. The Bourne shell is almost fully compatible with the Korn shell (upward compatible), so programs developed under the Bourne shell can still be executed on the Korn shell. The default value of the Korn shell prompt symbol is $. In Linux, the Korn shell is called pdksh, which refers to the Public Domain Korn Shell.
In addition to poor execution efficiency, the Korn shell is better in many aspects than the Bourne shell. However, it is difficult to compare the Korn shell with the C shell because both have their own strengths in many aspects, in terms of efficiency and ease of use, the Korn shell is superior to the C shell. I believe many users have a negative impression on the execution efficiency of the C Shell.
In terms of shell syntax, the Korn shell is close to the general programming language, and it has subprograms and provides more types of data. As for the Bourne shell, it has the least data types among the three shells and only provides string variables and Boolean types. In the overall consideration, the Korn shell is the performer among the three, followed by the C shell, and finally the Bourne shell. However, there are still other factors to consider in actual use, for example, speed is the most important choice, and it is likely to adopt the Bourne shell, because it is the most basic shell and the fastest execution speed.
Tcsh is a free software developed in recent years (the C shell in Linux actually uses tcsh) for execution. it is not a UNIX standard, but can be downloaded from many places. If you are a supporter of C shell, I suggest you try tcsh, because you can at least use it as a C shell. If you are willing to spend some time learning, you can also enjoy many of its new advantages, such:
1. tcsh provides a command line editing program.
2. provides the command column complementing function.
3. the spelling correction function is provided. It can automatically detect the command or word that is spelling incorrectly in the command column.
4. dangerous command detection and reminder function, to prevent you from accidentally executing the rm * command which is highly lethal.
5. provides a shortcut for common commands ).
Bash is backward compatible with the Bourne shell and incorporates many functions of C shell and Korn shell. These functions are actually available in C shell (including tcsh, of course), but they were not supported by Bourne shell in the past. Below I will introduce bash's six important improvements (detailed instructions for use I will introduce them in a later chapter ):
1. job contorl ). Bash supports signals and instructions about work, which will be mentioned later in this chapter.
2. alias function (aliases ). The alias command is used to create another name for a command. it operates like a macro and expands into the commands it represents. The alias does not replace the command name. it only gives that command another name.
3. command history ). BASH shell is added to the command history function provided by C shell. it records the commands you recently executed using the history tool. The command starts from 1. the default value is 500. The history tool program is a short-term memory that records your recent commands. To view these commands, you can type history in the command column. This will display the list of recently executed commands and add numbers in front.
Each of these commands is technically called an event. The event describes an action that has been taken (the executed command ). Events are numbered according to the execution order. the closer an event is, the larger the number it is. these events are identified by its number or command prefix. The history utility allows you to place an event in the command column and allow you to execute it by referring to the previous event. The simplest way is to place a history event on your command column at a time with the up/down key; you do not need to display the list with history first. One up key will place the last history event in your command column, and another one will place the next History event. Press the down key to place the previous event in the command column.
4. Command column editing program. BASH s
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.