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.
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
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
- 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
- 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.
- 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.
- 6. Text Command
The text command is used to judge an expression and produce a return value
- 7. Test judgment Symbol
Variables are best used in double quotes, and constants are best with single quotes
- 8. Shell Control Structure
If,case,for,while,until,break,continue,exit and so on, and C language is similar