当前位置:网站首页>shell 自定义函数
shell 自定义函数
2022-07-01 22:12:00 【响彻天堂丶】
1 语法
# 函数的定义
[ function ] funname ()
{
命令
[return 返回值]
}
# 调用函数
funname 传递参数1 传递参数2 ...
2 demo
#!/bin/bash
fun1()
{
echo "调用无参函数"
}
fun2()
{
echo "求两数的和..."
read -p "输入第一个数字: " n1
read -p "输入第二个数字: " n2
return $(($n1+$n2))
}
fun3()
{
echo "第一个参数为:${1}"
echo "第二个参数为:${2}"
return $(($1+$2))
}
#调用无参函数
fun1
#调用返回函数
fun2
rs=`echo $?`
echo "两数和为: ${rs}"
#调用第三个函数
fun3 2 2
rs=`echo $?`
echo "fun3 返回结果为: ${rs}"
边栏推荐
- Friendly serial assistant tutorial_ How to configure friendly serial port debugging assistant - tutorial on using friendly serial port debugging assistant
- Daily question brushing record (10)
- Unable to climb hill sort, directly insert sort
- Pytorch nn.functional.unfold()的简单理解与用法
- 思科--WAN 的概念考试外部工具
- Sogou wechat app reverse (II) so layer
- 陈天奇的机器学习编译课(免费)
- Pytorch's code for visualizing feature maps after training its own network
- Explain JMM in detail
- SAP 智能机器人流程自动化(iRPA)解决方案分享
猜你喜欢

Appium automated testing foundation - Supplement: introduction to desired capabilities parameters

Preparation of functional test report

Genicam gentl standard ver1.5 (4) Chapter 5 acquisition engine

Selection of all-optical technology in the park - Part 2

Explain the use of locksupport in detail

Flynk SQL client uses comparison and is familiar with official documents

el-input文本域字数限制,超过显示变红并禁止输入

104. SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目

Tcpdump command usage details

14年本科毕业,3个月转行软件测试月薪13.5k,32的岁我终于找对了方向
随机推荐
MySQL -- index of InnoDB storage engine
数字货币:影响深远的创新
[target tracking] | single target tracking indicator
使用3DMax制作一个象棋棋子
internal field separator
Demo program implementation of QT version Huarui camera
转载csdn文章操作
Appium自动化测试基础 — APPium安装(一)
Unable to climb hill sort, directly insert sort
redis配置文件中常用配置详解[通俗易懂]
Pytorch's code for visualizing feature maps after training its own network
转--利用C语言中的setjmp和longjmp,来实现异常捕获和协程
Vsphere+ and vsan+ are coming! VMware hybrid cloud focus: native, fast migration, mixed load
[JUC learning road day 9] barrier derivatives
Turn -- the underlying debugging principle of GDB is so simple
Use and function of spark analyze command map join broadcast join
Quantifiers of regular series
[daily training] 326 Power of 3
Use of locust
Daily question brushing record (10)