Embedded technology study notes (5)

Embedded Linux development tools: shell programming (script programming, used in batch processing)
Linux system operation and maintenance engineers need to be proficient in shell (system transplantation in embedded system development)
shell: 1, command parser, the user input commands Parse and call the corresponding executable file
2. Script language
command: The executable file
shell defines various variables and parameters, and provides many control structures that are only available in high-level languages, including loops and branches. Although it is not part of the Linux system kernel, it invokes most functions of the system kernel to execute programs, create documents, and coordinate the operation of various programs in a parallel manner.
In essence, shell script is a simple combination of command line commands into a file.
(1) Comments of the shell Comments in the
bash shell script
#! / Bin / sh
#shijiange 20181109 hello world
echo “Hello World!” #Hello world The
program must start with the following line (must be on the first line of the file):
#! / bin / sh
#! Used to tell the system that the following parameters are used to execute the program of the file.
To make the script executable:
chmod + x filename
execute your script by typing: ./filename
(2) shell variables
Shell script Each variable has a variable name, and the variable name has its naming rules
Naming rules: must be Uppercase letters, lowercase letters, underscores, numbers, and the first letter cannot be a number
1name does not meet the requirements
nam, e does not meet the requirements
my_name meets the requirements
_name meets the requirements
Shell default variable types are all strings, there is no need to specify the type
and the types of variables can be divided into internal variables (that is, the system comes) and custom variables ( Variables can be customized in the script) The
syntax of the custom variables is the variable name on the left and the value on the right. Shell custom variables Note = No spaces can appear on the left and right. After learning syntax such as java, the variable name = "shijiange" will be defined as such. Shell in the name will be interpreted as a command to
remove the variable value can be added to a dollar sign ($) in front of the variable
$ #: The number of incoming script command-line parameters
$ *: All command line parameter values between the various parameter values Leave a space
$ 0: the command itself (shell file name)
$ 1: the first command line parameter
$ 2: the second command line parameter
(3) the function of the shell
① if condition judgment
Bash Shell condition judgment syntax
if condition; then
# condition holds There can be multiple commands executed. Command block (it must be executed or not executed)
fi
if condition; then #The
condition is established to execute the command, there can be multiple commands. Command block
else #The
command that is executed if the condition is not satisfied, can be multiple commands
fi
conditions can have digital judgment, character string judgment, file judgment, etc.
②while loop
While loops tend to solve regular problems, such as output from 1 to 100
while loop syntax:
while condition; do
echo 'shijiange'
echo 'change condition' to
change the condition
done
③for loop
for loop tends to solve the problem of repeatability, loop processing Each line of text in the
for loop is very useful
for batch management of the server. By default, all blank characters are used to separate: tab, space, carriage return, and loop processing

Published 14 original articles · Like1 · Visits 477

Guess you like

Origin blog.csdn.net/a1152946932/article/details/105072493