当前位置:网站首页>Shell programming specifications and variables
Shell programming specifications and variables
2022-07-28 15:52:00 【Now a lemon】
List of articles
One 、Shell Script Overview
1. What is? Shell
Shell Is a command interpreter , It's on the outermost layer of the system , Responsible for direct dialogue with users , Explain user input to the operating system , And handle the output of various operating systems , Output to screen feedback to user . This kind of dialogue can be interactive or non interactive , The command we input is something else , Then we need a program to help us translate , Become a binary program that a computer can recognize , At the same time, the computer generated results are returned to us .
2.Shell The role of
Linux In the system Shell It's a special application , It lies between the operating system kernel and the user , Acting as a " command interpreter " Role , Be responsible for receiving and interpreting the operation instructions input by the user , Pass the operation to be performed to the kernel for execution , And output the execution result .
common Shell There are many kinds of interpreter programs , Use different Shell when , Its internal instructions 、 There are some differences in command line prompt and so on .
adopt /etc/shells The file can understand what the current system supports Shell Types of scripts 
/bin/sh # yes bash Soft links to commands
/bin/bash # Base on GNU Developed under the framework of Shell
/usr/bin/sh # Has been bash Replaced by
/usr/bin/bash #centos and redhat System default use bash shell( Interpreter )
/bin/txsh #csh Enhanced Edition , And csh Fully compatible and integrated csh, More features
/bin/csh # Has been /bin/bash Replaced by ( Integrate C shell, More features )
3.Shell What can a script do
- Automate the installation and deployment of software , Such as installation and deployment LAMP Architecture Services
- Complete the management of the system automatically , Such as adding users in batch
- Automate backup , Such as regular database backup
- Automated analytical processing , Such as website visits
4.Shell Script usage scenarios
- Repetitive operations
- Interactive tasks
- Batch transactions
- Service running status monitoring
- Scheduled task execution
Two 、Shell The composition of the script
1. Script declaration ( Interpreter ): If the first act "#!/bin/bash", Indicates that the code statement below this line is passed /bin/bash Program to explain the execution of ,#!/bin/bash Is the default interpreter . There are other types of interpreters , such as :#!/usr/bin/python、#!/usr/bin/expect
2. Annotation information : With "#" The opening statement is expressed as a comment message , The annotated statement will not be executed when the script is run again
3. Executable statement : such as echo command , For output " " String between 


3、 ... and 、Shell Script execution
1. Method 1 : Specify the path
Command to specify the path , It is required that the document must have x jurisdiction 
Specify the absolute path 
Specify the relative path 
2. Method 2 : Appoint Shell
Appoint Shell To explain the script , It is not required that the document must have x jurisdiction
sh Script path 
soucre Script path 
bash Script path 
Four 、 Redirection and pipeline operation
1. Pipeline operation "|"
The pipe symbol "|" The command output on the left , As input to the command on the right ( Deal with people ), Multiple pipes can be used in the same command line 
2. Redirect
2.1 Interactive hardware devices
| type | Device file | Document description number | Default device |
|---|---|---|---|
| The standard input | /dev/stdin | 0 | keyboard |
| standard output | /dev/stdout | 1 | Monitor |
| Standard error output | /dev/stderr | 2 | Monitor |
2.2 Redirection operation

Redirect output 
Overwrite the contents of the original file 
Redirect input 

Error output
summary
边栏推荐
- Has won Huawei's 8.5 billion yuan screen order? Vicino responded: the customer asked for confidentiality and could not reply!
- 突发!微星CEO江胜昌坠楼身亡
- Camera continuous shooting automatic test shell script
- Software architecture and design (x) -- Architecture Technology
- PXE network installation
- How to quickly access the unified authentication system
- Preparing for listing in the United States? Arm announced that it would divest the Internet of things service business: the future will focus on the underlying chip design
- 玩死原型链
- 已拿下华为85亿元屏幕订单?维信诺回应:客户要求保密,无法回复!
- Samba Server Setup Guide
猜你喜欢

Summarize the knowledge points of the ten JVM modules. If you don't believe it, you still don't understand it

shell编程规范与变量

管理区解耦架构见过吗?能帮客户搞定大难题的

Event express | Apache Doris Performance Optimization Practice Series live broadcast course is open at the beginning. You are cordially invited to participate!

软件架构与设计(十)-----架构技术

2路DI高速脉冲计数器1路编码器转Modbus TCP有线无线模块IBF161

软件架构与设计(一)-----关键原则

Software architecture and design (I) -- key principles

12V脉冲转速测量转24V电平信号转换变送器

Proportional solenoid valve control valve 4-20mA to 0-165ma/330ma signal isolation amplifier
随机推荐
Docker实现Redis Cluster(集群)模式 哈希槽分区进行亿级数据存储
Virturalbox solves the problem of kernel driver
知识点qwer
Framework customization series (VI) -- shield fallbackhome mobile phone from pop-up during startup and directly enter the launcher
Deutsche Telekom denied strengthening its cooperation with Huawei and said it had reduced its cooperation with Huawei in the past three years
热敏电阻PT100,NTC转0-10V/4-20mA转换器
Software architecture and design (V) -- data centric architecture
Proportional solenoid valve control valve 4-20mA to 0-165ma/330ma signal isolation amplifier
5路DI/DO继电器输出远程IO采集模块Modbus TCP/IBF95
记录一下 clearfix 清除浮动
Flutter中是使用RxDart代替Stateful
Matlab does not overwrite importing Excel
Software architecture and design (IX) -- component based architecture
PXE network installation
Shell programming specifications and variables
samba服务器如何配置
monkey压力测试
Canoe tutorial
28.55亿元!青岛芯恩增资完成:兴橙集电成第一大股东,持股57.10%
Using SYSTEMd to manage services