当前位置:网站首页>shell脚本
shell脚本
2022-08-02 08:20:00 【吃不饱肉的猫】
1.什么是shell脚本
Shell脚本与Windows/Dos下的批处理相似,也就是用各类命令预先放入到一个文件中,方便一次性执行的一个程序文件,主要是方便管理员进行设置或者管理用的。但是它比Windows下的批处理更强大,比用其他编程程序编辑的程序效率更高,它使用了Linux/Unix下的命令。 Shell是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁。Shell 既是一种命令语言,又是一种程序设计语言。
2.Shell变量
创建一个文件:文件名.sh 并且设置为有读写执行的权限
进入文件中开头必须为:#!bin/bash,然后,echo"你要写得内容",要输出的内容,保存退出。
# 定义变量
name="king"
# 使用变量${变量}或者使用$ 变量
echo "${name} 来自斯里兰卡"
3.Shell 传递参数
执行 Shell 脚本时,向脚本传递参数,脚本内获取参数的格式为:$n。n 代表一个数字,1 为执行脚本的第一个参数,2 为执行脚本的第二个参数,以此类推……
./文件名.sh 参数值1,参数值2 ......把第一个参数值赋值到$0,以此类推输出你写得内容。
4.Shell 数组
数组中可以存放多个值。Bash Shell 只支持一维数组(不支持多维数组),初始化时不需要定义数组大小(与 PHP 类似)
语法格式如下:
数组=("值1",值2......)
${数组名[下标]}
5.基本运算符
1.算数运算符
2.关系运算符
3.布尔运算符
4.字符串运算符
5.文件测试运算符
两个数相加(注意使用的是反引号 *`* 而不是单引号 *'*)
表达式和运算符之间要有空格,2+2 是不对的,必须写成 2 + 2。
6.关系运算符
关系运算符只支持数字,不支持字符串,除非字符串的值是数字 。
7.布尔运算符
8.Shell 流程控制
if [ $(ps -ef | grep -c "ssh") -gt 1 ]; then echo "true"; fi
ps -ef | grep -c "mysql"统计某个进程的个数
边栏推荐
- Axial Turbine Privacy Policy
- Docker内MySQL主从复制学习,以及遇到的一些问题
- 三维体尺测量
- 轴流式水轮机隐私政策
- (Note) AXIS ACASIS DT-3608 Dual-bay Hard Disk Array Box RAID Setting
- postman使用方法
- R language plotly visualization: plotly visualizes the scatter plot of the actual value of the regression model and the predicted value of the regression, analyzes the prediction performance of the re
- PyCharm usage tutorial (more detailed, picture + text)
- R language plotly visualization: use the plotly visualization model to predict the true positive rate (True positive) TPR and false positive rate (False positive) FPR curve under different thresholds
- postman下载安装汉化及使用
猜你喜欢
PyQt5 (a) PyQt5 installation and configuration, read from the folder and display images, simulation to generate the sketch image
C Language Basics_Union
[OC学习笔记]weak的实现原理
Three types of [OC learning notes] Block
【开源项目】X-TRACK源码分析
PyQt5(一) PyQt5安装及配置,从文件夹读取图片并显示,模拟生成素描图像
A young man with strong blood and energy actually became a housekeeper. How did he successfully turn around and change careers?
Biotin-EDA|CAS:111790-37-5| Ethylenediamine biotin
二分类和多分类
How Engineers Treat Open Source --- A veteran engineer's heartfelt words
随机推荐
Detailed explanation of calculation commands in shell (expr, (()), $[], let, bc )
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之一:解题思路
PostgreSQL learning summary (11) - PostgreSQL commonly used high-availability cluster solutions
In a recent build figure SLAM, and locate the progress
Biotin hydrazide HCl|CAS:66640-86-6|生物素-酰肼盐酸盐
Gorilla Mux 和 GORM 的使用方法
Spark 系统性学习笔记系列
day——05 迭代器,生成器
QT web 开发 - 笔记 - 3
Biotin-LC-Hydrazide|CAS:109276-34-8|生物素-LC-酰肼
C语言_指针
查看变量的数据格式
Docker内MySQL主从复制学习,以及遇到的一些问题
那些年我们踩过的 Flink 坑系列
类和对象【下】
Figure robot software digital twin station oil and gas pipelines, oil and gas transportation control platform
Biotin hydrazide HCl|CAS:66640-86-6|Biotin-hydrazide hydrochloride
MySQL Workbench 安装及使用
etcd implements large-scale service governance application combat
mysql 中 in 的用法