当前位置:网站首页>shell函数
shell函数
2022-08-05 05:10:00 【1701y】
目录
shell函数
将命令序列按格式写在一起
可方便重复使用命令序列
shell函数定义
function 函数名 {
命令序列
}
函数名 () {
命令序列
}
shell函数调用
1 直接写 函数中调用函数 直接写函数名
2 同名函数,后一个生效
3 调用函数一定要先定义
4 只要先定义了调用的,其他函数定义顺序无关
declare -F ##查看当前系统的所有函数

declare -f 查看当前系统的所有函数的定义规则

写一个判断操作系统的函数


函数返回值
return表示退出函数并返回一个退出值,脚本中可以用$?变量显示该值
使用原则:
函数一结束就取返回值,因为$?变量只返回执行的最后一条命令的退出状态码
退出状态必须是0~255,超出时值将为除以256取余

函数传参


函数的变量的作用范围


由此看出函数内部定义变量会影响外部变量的使用


函数递归
阶乘


边栏推荐
猜你喜欢

how to measure distance from point to face in creo

ESP32 485光照度

How can Flutter parent and child components receive click events

Day019 Method overriding and introduction of related classes

Qt制作18帧丘比特表白意中人、是你的丘比特嘛!!!

结构光三维重建(二)线结构光三维重建

App rapid development and construction experience: the importance of small programs + custom plug-ins

The log causes these pits in the thread block, you have to guard against

Using QR codes to solve fixed asset management challenges

Flutter学习5-集成-打包-发布
随机推荐
Feature preprocessing
uva1325
Day14 jenkins部署
LAB 信号量实现细节
u-boot中的u-boot,dm-pre-reloc
In the hot summer, teach you to use Xiaomi smart home accessories + Raspberry Pi 4 to connect to Apple HomeKit
【cesium】元素高亮显示
Excel画图
【软考 系统架构设计师】软件架构设计③ 特定领域软件架构(DSSA)
[WeChat applet] WXML template syntax - conditional rendering
C#关于set()和get()方法的理解及使用
软件管理rpm
Analyses the mainstream across technology solutions
LAB Semaphore Implementation Details
Requests库部署与常用函数讲解
Using QR codes to solve fixed asset management challenges
8.04 Day35-----MVC三层架构
Detailed explanation of Mysql's undo log
结构光三维重建(二)线结构光三维重建
uva1325