Here we will first introduce the basic syntax of shell, including the beginning, comment, variables, and environment variables, however, laying a good foundation is a prerequisite for easy learning in the future.
1. Linux script compiling Basics
◆ 1.1 Basic syntax Introduction
Start with 1.1.1
Program The following line must start (the first line of the file must start ):
#! /Bin/sh
Symbol #! The parameter used to tell the system that the program is used to execute the file. In this example, we use/bin/sh to execute the program.
When editing a script, you must make it executable if you want to execute it.
To make the script executable:
Compile chmod + x filename to run it with./filename.
1.1.2 notes
During shell programming, a sentence starting with # represents a comment until the end of this line. We sincerely recommend that you use annotations in your program.
If you have used annotations, you can understand the role and working principle of the script in a short time even if the script is not used for a long time.
1.1.3 Variables
In otherProgramming Language You must use the variable. In shell programming, all variables are composed of strings, and you do not need to declare variables. To assign a value to a variable, you can write as follows:
#! /Bin/sh
# Assign values to variables:
A = "Hello World"
# Print the content of variable:
Echo "A is :"
Echo $
Sometimes the variable name is easily confused with other words, such:
Num = 2
Echo "this is the $ numnd"
This does not print "this is the 2nd", but only prints "this is the", because shell will search for the value of the variable numnd, but there is no value for this variable. We can use curly braces to tell shell that we want to print the num variable:
Num = 2
Echo "this is the $ {num} Nd"
This will print: This is the 2nd
1.1.4 Environment Variables
Variables processed by the Export keyword are called environment variables. We will not discuss environment variables, because generally, only environment variables are used in the login script.
here we will introduce the basic content of the Linux Shell script.