Deep Analysis of Type mode Linux shell Programming

Source: Internet
Author: User
Tags linux shell commands

Before giving you a detailed introduction to the Linux shell, let's first understand the shell and then give a comprehensive introduction to the Linux shell, hoping to be useful to you. Linux shell has multiple types, of which the most common types are Bourne shellsh), C shellcsh), and Korn shellksh ). Each of the three shells has its own advantages and disadvantages. The Bourne shell is the original shell used by UNIX and can be used on every UNIX.

Linux shell types

Bourne shell is excellent in Linux shell programming, but it is inferior to several other shells in dealing with user interactions. In Linux shell, the default shell is the Bourne Again shell, which is an extension of the Bourne shell, Bash for short. It is completely backward compatible with the Bourne shell, in addition, many features are added and enhanced based on the Bourne shell. Bash is placed in/bin/bash. It has many features, such as command completion, command editing, and command history table, it also contains many advantages of C shell and Korn shell, flexible and powerful programming interfaces, and friendly user interfaces.

C shell is a Linux shell that is more suitable for programming than the Bourne shell. Its syntax is similar to that of C. Linux shell provides Tcsh for people who like to use C shell. Tcsh is an extension of C shell. Tcsh includes command line editing, programmable word completion, spelling correction, historical command replacement, Job control, and syntax similar to C language. It is not only compatible with Bash shell as a prompt, it also provides more prompt parameters than Bash shell.

The Korn shell combines the advantages of C shell and Bourne shell and is fully compatible with the Bourne shell. The Linux shell system provides the pdkshksh extension. It supports task control and can be suspended on the command line, executed in the background, wakened or terminated.

Linux shell does not neglect other Linux shell users. It also includes some popular Linux shells such as ash and zsh. Each shell has its purpose. Some shells have patents, and some can be obtained from the Internet or other sources. To decide which Linux shell to use, read the online help of various Linux shells and try it out.

When you log on to the Linux shell, the/etc/passwd file determines which Linux shell to use. For example:
# Fgrep lisa/etc/passwd
Lisa: x: 500: 500: TurboLinux User:/home/lisa:/bin/bash
Shell is listed at the end of each row/bin/bash ).
As Bash is the default shell in Linux shell, this chapter mainly introduces Bash and its related knowledge.

Linux shell commands

When you log on to the Linux shell system as a command line c user, you can see a shell prompt that identifies the start of the command line. You can enter any commands and parameters at the end of the prompt. Example: $ date

CST 1999

When a user logs on, the user actually enters the Linux shell, which follows certain syntax to explain the input command and pass it to the system. The first word entered in the command line must be the name of a command, and the second word is the option or parameter of the command. Each word in the command line must be separated by spaces or tabs. The format is as follows: $ Command Option Arguments

Options and Parameters

The option is a code that contains one or more letters. It must be preceded by a minus sign. Linux shell uses it to differentiate options and parameters ), option can be used to change the type of the command execution action. For example:

Ls motd passwd

This is an ls command without any options. It can list all files in the current directory, only the names of each file are listed, and no more information is displayed.
$ Ls-l total 2-rw-r -- 2 wzh book 22 Apr 20 motd-rw-r -- 2 wzh book 796 Apr 20 passwd
The-l option is added to list a row of information for each file, such as the data size and the last modification time. Most commands are designed to accept parameters. A parameter is one or more words entered after the option in the command line, for example:
$ Ls-l text-rw-r -- 2 wzh book 22 Apr 20 motd-rw-r -- 2 wzh book 796 Apr 20 passwd

All files in the text directory and their information are displayed. Some commands, such as ls, can contain parameters, while some commands may require some minimum parameters. For example, the cp Command requires at least two parameters. If the number of parameters does not meet the command requirements, the Linux shell will provide an error message. For example:
$ Cp-I mydata newdata note: the options in the command line are prior to parameter input.

Linux shell Command Line Features

The command line is actually a text buffer that can be edited. You can edit the input text before pressing enter. For example, you can use the BACKSPACE key to delete the just-typed characters, delete the entire line, and insert characters so that when you enter commands, especially complex commands, an error occurs, you do not need to re-enter the entire command. You can use the edit operation to correct the error. The up arrow can be used to re-display the just-executed command. This function can be used to re-execute the previously executed command without re-typing the command.
Bash stores the list of commands you have previously typed. This list is called the command history table. Click the arrow to display each command on the command line. Similarly, you can move the down arrow in the command list to display previous commands on the command line. You can modify and execute these commands. This feature is described in detail in section 10.4.

Multiple commands can also be placed in a command line and separated by semicolons. For example:
$ Ls-F; cp-I mydata newdata
You can also enter a command in several command lines and use a backslash to continue a command line to the next line.
$ Cp-I
Mydata
Newdata
The preceding cp command is input in three lines. The first two lines end with a backslash and use the three lines as one command line.
The preceding describes various types of Linux shell files.

  1. Comprehensive Analysis and Discussion of Linux Shell Programming
  2. Brief Introduction to the Collection programming language of Linux shell commands
  3. Linux shell
  4. Teach you three methods of automatic Linux Shell Interaction
  5. Change the output of linux shell

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.