Linux shell programming 1 ---- shell script programming basics 1 What is shell script 1 shell is not only a command interpreter but also a programming language, a program written in shell is similar to a batch processing program in DOS. 2. A user can store a series of commands in the file. Generally, a program written in shell is called a shell script or a shell program 3, the combination of variables and flow control will produce a powerful programming tool. The shell scripting language is very good at processing text-type data. Because all configuration files in Linux are plain text, therefore, the shell scripting language plays a huge role in the management of Linux systems. 2. Composition of shell scripts. 1. shell scripts are in the unit of action. When executing scripts, they are split into one row and one row for execution, the main components contained in the script include comments, commands, shell variables, and structure control statements. 2. Note: The comments are used to explain and describe the script, add the symbol # Before the comment line, so that shell will not explain the line when executing the script. 3 command: in shell scripts, any interactive command 4 variables can be used: shell supports two data types: string variables and Integer Variables 5 structure control statements: create and execute a shell script 3. You can use any text editor to create a shell script file, such as vi, gedit and so on. There are two ways to execute shell scripts. One is to use the file name Shell Command Parameters, call format sh file name 2 Another is. /file name. However, when we execute this part of the script file, we are prompted that we do not have the execution permission. Therefore, when we execute this part in the second method, we must change the permission of this file, so that it has the execution permission. 3. When a script file is executed, shell generates a sub-shell (that is, a sub-process) to execute commands in the command, therefore, the variable value in the file cannot be passed to the shell 4 shell script encoding specification 1 the correct starting part of a bash script should be #! Start :#! /Bin/bash 2 #! The statement at the beginning informs the system to use the interpreter to execute the script. 3 if the default shell is bash, you do not need to write it, however, a good shell coding specification requires that we must specify what interpreter is used to perform analysis on 5 shell instances. 1 first, the default shell in ubuntu is dash, THE sh in ubuntu is only the link of the default shell, we can use ls/bin/sh-l to view the default shell 2. We can use the following two methods to change the default shell 1 sudo dpkg-reconfigure dash, then select no or no and confirm. In this way, dash will be reconfigured, and it will not be used as the default shell tool 2. You can also directly modify the/bin/sh link file, sudo ln-fs/bin/bash/bin/sh specify it to/bin/bash. 3. Next we will create a shell script named s. sh 4. Next we will use two methods to execute it. In the second method, we need to change the permission first.