Linux shell Programming

Source: Internet
Author: User

    1. 1. What is Shell

The shell is the user interface of the system and provides an interface (command interpreter) for the user to interact with the kernel. The shell receives the user's input command and feeds it into the kernel to perform the role of coordinating the interaction between the user and the system.

    1. 2, Shell script General execution Process

A shell script is a file that contains several lines of shell or Linux commands. For a large number of commands that are written and used more than once, you can use the files to save them for later use.

Usually the shell script, the first line must indicate which shell the system needs to interpret the user's shell program, by default, #! Bin/bash

Execution process:

Method One: chmod 777 run.sh plus executable permissions

./run.sh then executes

Method two: Bash./run.sh based on the type of shell script (default bash), select shell Program

Write a run.sh file, run.sh file main.c file compilation link to main file

After running the run.sh file, it is visible that the original directory has more MAIN,MAIN.O files

Run main file, visible run result

    1. 3. Input/Output redirection

Linux uses standard input stdin and standard output stdout to represent the input and output of each command, and also uses a standard error output stderr for output error messages. Also available in 0, 1, 2 for standard input, standard output, and standard error message output

Output redirection using ' < ' can be implemented with input redirection using > representation

A, the control of the standard input

Syntax: Command < file, input of file as command

For example:

Mail-s "Mail Lee" [email protected] < LEE1

The file lee1 as the content of the letter, the subject name is Mail Lee, sent to the recipient

PS: This did not try, interested can try

B, the control of the standard output

Syntax: commands > Files

Sends execution results of the command to the specified file

Syntax: Commands >> files
Attaches the result of the command execution to the specified file

    1. 4. Special characters in the shell

$ denotes variable substitution, which replaces the variable with the value of the variable specified later

"Characters enclosed in double quotation marks, except $, inverted quotation marks ('), and backslashes (\) still retain their functionality, and the remaining characters are treated as ordinary characters nonspacing

' single quote-enclosed character nonalphanumeric appears as a normal character.

' The enclosing child is interpreted by the shell as the command line, and when executed, the shell executes the command line first and replaces the entire inverted quotation mark with its standard output result.

    1. 5. Shell Variables

Variable classification: System variables, environment variables, and user variables

System variables are used in judging the parameters and the return value of the command, the environment variables are mainly set when the program is run, and the user variables are used in the programming process.

    1. 6. Text Command

The text command is used to judge an expression and produce a return value

    1. 7. Test judgment Symbol

Variables are best used in double quotes, and constants are best with single quotes

    1. 8. Shell Control Structure

If,case,for,while,until,break,continue,exit and so on, and C language is similar

Linux shell Programming

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.