1. Process:
The process of shell applications is generally interactive and broadly divided into GUI and CLI
GUI (graphical user Interface, referred to as GUI, also known as graphical user interface) is a graphical display of the computer operating user interface, support mouse, desktop and other peripherals, more famous windows, Android
The CLI (command-line interface, command line interface) refers to the interface that can type executable instructions at the user prompt, it usually does not support the mouse, the user enters the instruction through the keyboard, the computer receives the instruction, executes.
The morphology of the CLI is generally composed of commands, options, parameters, and is divided into built-in commands and external commands
2, the way of implementation:
Since Linux scripts or program source files are generally text files, there are generally two ways to execute a Linux script:
Delegates are: C, C + +
② explanation execution: The interpreter is involved in the whole process, one line at a time. Representatives are: Python and bash
Python: Generally have written a good programming library, the user through the Write program control structure, call the programming library to complete the program writing;
Library file: Typically a function module, which can be called directly in programming or through its API.
Bash: Need to write from scratch, but also program control structure, but need to call the machine command program files to write programs;
External commands: Generally provided by each application;
3. Program: A collection of instructions and data or algorithms and data generally written for the purpose of achieving a certain user
Depending on the focus, it can be divided into procedural programming and object-based programming:
Program programming: Command-centric, design algorithms, data services to algorithms;
Object-Oriented Programming: Data-centric, design-based data structures (classes), programs to serve data structures;
Bash depending on the situation, bash programming can be divided into three categories of execution: Sequential execution: Execution by Selection: execution of only one of the branches if...fi,if...elif...else...fi loop execution: A piece of code to execute 0,1 or more while,if ... elif...else...fi
Programming elements of Bash: variables, processes, functions
① variables: Local variables, environment variables, local variables, positional parameter variables, and special variables (built-in variables) can be classified according to different situations
Naming rules for variables: Only numbers, letters, and underscores, and cannot start with numbers;
Reference variable: ${name}, $name
A reference to a variable:
Weak reference: "", its internal variable reference will be replaced by the value of the variable;
Strong reference: ', the variable reference of its variable will keep the original character;
Command reference: ' Command ', $ (command), the execution result of the reference command;
Declared as integral type:
Declare-i Name=[value] -i: Integer variable
Let Name=value
View all variables: Set
Destroyed:
Automatic destruction: Shell process termination;
Manual destruction: unset name
Bash's variable use characteristics: weak type, without prior declaration;
Local variables: Used in the user's current shell lifetime script, only meaningful for the user's present shell lifetime. If you start another process or exit in the shell, this value will not be valid. The advantage of this method is that the user cannot set this variable for another shell or process to be valid.
Set a local variable in the format:
$ Variable-name=value or $ {variable-name=value}
Variable-name: Variable Name
=: Assignment Symbol
Value: Variable values
Note: There can be spaces on both sides of the equals sign. If the value contains spaces, you must enclose them in double quotation marks. Shell variables can use uppercase and lowercase letters, and when using variables, you can prevent the shell from misreading the value of the variable if enclosed in curly braces. (see section I for details)
Environment variables: Local variables that are "exported" and can be used in all user processes. The logon process is the parent process, and the shell process is a child process. The parent process initializes the environment variable, and the child process is ready to use.
Configuration file for Environment variables
/etc/profile (for all users) Or/home/user/.bash_profile (action for user users)
Command for variable declarations:
Export Name=[value]
Declare-x Name[=value]- x: Environment Variables
View all environment variables: env, PRINTENV, export
Destroy: unset name (see content II for details)
Local variables: They are limited to the shell in which they are created. The local function can be used to create locals, but only within functions. A local variable can be set by simply assigning it a value or a variable name, set with declare built-in function, or omit it, and a function executes the process;
Declare variable name = value
Positional parameter variables: references to parameters passed to the script in the script, arguments passed to the function in the function, parameter related numbers passed in the script, this number can be arbitrarily many, but only the first 9 can be accessed, using the shift command can change the limit; The parameter starts at the first and ends at Nineth; A $ sign is added before each access parameter, and the first parameter is 0, which indicates that the actual script name is reserved and is available regardless of whether the script has parameters.
$: script name. This variable contains the address, and you can use basename $ to get the script name.
$: First parameter
$2,$3,$4,$5,... One analogy.
Special variables: $?, $*, [email protected], $#, $$,$-,$!
The specific shell variables are as follows:
$# the number of arguments passed to the script;
$* displays all parameters passed to the script in a single string. Unlike positional variables, this option can have more than 9 parameters;
$$ the current process ID number for the script to run;
$! Process ID number of the last process running in the background;
[Email protected] is the same as $*, but quotes are used, and each parameter is returned in quotation marks;
$-Displays the current options used by the shell, as with the SET command function;
$? Displays the exit status of the last command. 0 means there is no error, and any other value indicates an error;
[[email protected] ~]# echo $$31253[[email protected] ~]# echo $-himbh[[email protected] ~]# echo $?0
Content one:[[email protected] ~]# name=nicai #设定本地变量 [[email protected] ~]# echo $name #打印输出nicai [[email protected] ~]# bash #进入下一级本地变量 [[email protected] ~]# echo $name [[email protected] ~]# exitexit[[email protected] ~]# echo $name nicai[[email protected] ~]# [[email protected] ~]# pstreesystemd─┬─alihids───9*[{alihids}] ├─AliYunDun───8*[{AliYunDun}] ├─aliyundunupdate───6*[{aliyundunupdate}] ├─agetty ├─crond ├─dbus-daemon ├─gshelld───3*[{gshelld}] ├─iprdump &nBsp; ├─iprinit ├─iprupdate ├─lvmetad ├─nscd───7*[{nscd}] ├─ntpd ├─rsyslogd───2*[{rsyslogd}] ├─sshd───sshd───bash───pstree #有内容的本地变量 ├─systemd-journal ├─systemd-logind └─systemd-udevd[[email protected] ~]# bash[[email protected] ~]# pstreesystemd─┬─alihids───9*[{alihids}] ├─aliyundun───8*[{aliyundun}] ├─aliyundunupdate───6*[{ Aliyundunupdate}] ├─agetty &nBsp; ├─crond ├─dbus-daemon ├─gshelld───3*[{gshelld}] ├─iprdump ├─iprinit ├─iprupdate ├─lvmetad ├─nscd───7*[{nscd}] ├─ntpd ├─rsyslogd───2*[{rsyslogd}] ├─sshd───sshd───bash───bash───pstree ├─systemd-journal ├─systemd-logind └─systemd-udevd[[email protected] ~]#
Content two:[[email protected] ~]# name=nicai #本地变量 [[email protected] ~]# echo $namenicai [[Email protected] ~]# bash[[email protected] ~]# echo $name [[email protected] ~]# exitexit[[email protected] ~]# echo $ namenicai[[email protected] ~]# export name[=aaa]-bash: export: ' name[=aaa] ': not a valid identifier[[email protected] ~]# export name=[aaa] # environment variable [[email protected] ~]# echo $name [aaa][[email protected] ~]# bash[[ email protected] ~]# echo $name [aaa][[email protected] ~]# [[email Protected] ~]# envxdg_session_id=466hostname=iz28qzns9m4zshell=/bin/bashterm=xtermhistsize=1000ssh_ CLIENT=61.182.229.120 60276 22SSH_TTY=/DEV/PTS/0USER=ROOTNAME=[BBB] ... [[Email protected] ~]# unset name[[email protected] ~]# echo $name [[email protected] ~]#
Linux processes, execution methods, programs, programming elements