当前位置:网站首页>Getting started with shell programming base
Getting started with shell programming base
2022-07-27 18:06:00 【Finger sword】
1、 What is? Shell
2、 What is? Shell Script
3、Shell Scripting language type
4、 Script creation and execution 、 stop it
5、 Basic operators of scripts
1、 What is? Shell
Shell Is a command interpreter , His role is to interpret and execute commands and programs entered by users , The user enters a command , It executes a , The way of dialogue that can get an immediate response is called " Interaction "
Shell It exists in the outermost layer of the operating system , Responsible for direct dialogue with users , Interpret the commands entered by the user to the operating system , And process the output of various operating systems , Then output to Mingming and return to the user ; for example , stay Linux System users enter user name and password and log in to Linux All operations are performed by Shell Explain and execute .
from ’Shell’ English definitions of words are available , command interpreter (Shell) It means shell , From the picture Shell Like a shell, it wraps the core of the system
2、 What is? Shell Script
When a command or program statement is not executed on the command line , It's executed through a program file , The program can become Shell Script , Generally speaking, it means writing a lot of commands into the script , Again by Shell perform , It's called Shell Script , This way of executing scripts through files is called non interactive , stay Windows Next , This is called ‘Dos Batch program ’
Example : eliminate /var/log/ Under the message Log files
Must be root User execution
#!/bin/bash
cd /var/log
cat /dev/null > messages
echo "Logs Cleaned up."3、Shell Scripting language type
1、Shell Script language in Unix/Linux There are two main categories Shell: One is Bourne Shell 、 One is C Shell
1.Bourne shell
Include Bourne shell(sh)、 Korn shell(ksh) 、Bourne Again Shell(bash) Three
2.C shell
Include csh 、 tcsh Two kinds of
Check... Supported by the system Shell
#[[email protected] ~] # cat /etc/shells2、 Other common scripting languages
①PHP Language
②Perl Language
③Python Language
3、Linux Check the system default Shell
Law 1
[[email protected] ~] # echo $SHELL
Law two :
[[email protected] ~] # grep root /etc/passwd4、 Script creation and execution
1、 At the beginning of the script ( first line ) It will indicate which interpreter executes the content in the script in the following form , as follows
#!/bin/bash
or
#!/bin/sh1、 Write a simple script , The conditions are as follows
1、 stay /root/ Create the script under , Name it test.sh 2、 Turn off firewall (firewalld) 3、 Turn off firewall self startup 4、 Set up Selinux The security module is in allow mode 5、 Change the hostname to test 6、 View current time 7、 Delete the script after execution
#!/bin/bash
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
hostnamectl set-hostname test
date
echo "Execution completed !"
rm -rf /root/test.sh2、 utilize while Output
#!/bin/bash
while [ 1 -gt 0 ]
do
sleep 1
echo 'Welcome to China !'
doneHere is the use of while Statement to output circularly , Be careful [] There must be a space between brackets and numbers , Can't be together , there -gt Means greater than , if 1>0 Conditions established , Then execute
2、 Script execution
1、 Use . Add the file name or absolute path , There is a space after dot
2、 Use the interpreter to execute , as follows :
3、 Use source
3. Termination of script
CTRL + C
5、 Basic operators of scripts
Operator | explain |
|---|---|
-eq | Check whether two numbers are equal , Equal return true. |
-ne | Check if two numbers are not equal , Unequal return true. |
-gt | Check whether the number on the left is greater than that on the right , If it is , Then return to true. |
-lt | Check if the number on the left is less than the number on the right , If it is , Then return to true. |
-ge | Check whether the number on the left is equal to or greater than the number on the right , If it is , Then return to true. |
-le | Check whether the number on the left is less than or equal to the number on the right , If it is , Then return to true. |
边栏推荐
- Database hyperphone (II)
- TCP connection status identification (syn, fin, ACK, PSH, RST, urg)
- Wechat applet cloud function batch delete multiple data error: errcode: -502005 database collection not exists
- Machine learning: IOU of concept understanding
- From digitalization to intelligent operation and maintenance: what are the values and challenges?
- 【数据库系统概论(王珊)】第11章 并发控制
- 数据库超话(一)
- WebDriverException( selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executabl
- 每条你收藏的资讯背后,都离不开TA
- 数据库超话(三)
猜你喜欢

机器学习之评价指标(二)——分类评价指标

卷积神经网络之卷积计算过程个人理解

Application of knowing things and learning | correlation graph analysis in anti cheating business

Personal understanding of convolution calculation process of convolution neural network

JSP自定义标签(下)

From digitalization to intelligent operation and maintenance: what are the values and challenges?

微信小程序 实现拨打电话

The Ministry of industry and information technology re governs data security, and Netease Yidun "privacy compliance" keeps the bottom line of enterprise operation

2022 safety officer-c certificate special operation certificate examination question bank and answers

卷积神经网络——SSD论文翻译
随机推荐
Some suggestions for writing original technical articles
如何限制root远程登入,使普通用户拥有root权限
知物由学 | SO加固如何提升Android应用的安全性?
Explain the idempotence of distributed system in detail
快解析结合海典医药
Convolutional neural network -- SSD thesis translation
Machine learning: IOU of concept understanding
Does PostgreSQL 14 support winserver2022?
知物由学 | 易盾移动端同构实践,几步改善官网交互体验
Zhengzhou University database course resource description
[single chip microcomputer] 2.1 hardware composition of AT89S52 single chip microcomputer
Behind every piece of information you collect, you can't live without TA
选择体育场馆的LED显示屏时应该注重哪些方面
The Ministry of industry and information technology re governs data security, and Netease Yidun "privacy compliance" keeps the bottom line of enterprise operation
【Codeforces】 B. Make it Divisible by 25
How to resolve the public domain name to the intranet IP server -- quickly resolve the domain name and map the Internet access
卷积神经网络——YOLOV2(YOLO9000)论文翻译
Notes on standardized management of "ancestral warehouse" of meituan meal
How to restrict root remote login so that ordinary users have root privileges
Taishan Office Technology Lecture: word strange paragraph borders