当前位置:网站首页>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
边栏推荐
- Transformation principle of voltage and frequency
- 如何压缩与解压缩ramdisk.img
- NTC,PT100热电阻转4-20mA温度信号转换器
- Multipurpose mixed signal 8ai/4di/do to serial port rs485/232modbus acquisition module ibf30
- Pytorch - optimize model parameters
- Regular expression (4)
- 热敏电阻PT100,NTC转0-10V/4-20mA转换器
- What are the process specifications of software testing? How to do it?
- 0-75mv/0-100mv to rs485/232 communication interface Modbus RTU acquisition module ibf8
- A wave of operation to solve the error problem of Laya scene editor
猜你喜欢

Encoder high speed pulse counter Modbus RTU module ibf150

Learn about the native application management platform of rainbow cloud

0-75mv/0-100mv to rs485/232 communication interface Modbus RTU acquisition module ibf8

What is the concept of game testing? What are the test methods and processes?

How as makes intelligent prompts regardless of case

How to quickly access the unified authentication system

Perception of life

Open light input / relay output rs485/232 remote data acquisition IO module ibf70

高速计数器转RS485Modbus RTU模块IBF150

Rongyun real-time community solution
随机推荐
samba服务器如何配置
Framework定制系列(六)-----屏蔽FallbackHome手机启动中弹窗直接进入Launcher
Matlab does not overwrite importing Excel
热敏电阻PT100,NTC转0-10V/4-20mA转换器
生命的感悟
活动速递| Apache Doris 性能优化实战系列直播课程初公开,诚邀您来参加!
Camera continuous shooting automatic test shell script
What are the process specifications of software testing? How to do it?
一波骚操作解决Laya场景编辑器报错问题
有道云笔记去除底部广告
管理区解耦架构见过吗?能帮客户搞定大难题的
monkey压力测试
NTC,PT100热电阻转4-20mA温度信号转换器
File and directory operations (5)
Several slips of X rust, those things that have to be said
知识点qwer
软件架构与设计(六)-----层次结构体
学习方法123
Proportional solenoid valve control valve 4-20mA to 0-165ma/330ma signal isolation amplifier
Minimum heap improves the efficiency of each sort