当前位置:网站首页>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}"
边栏推荐
- QStringList 的常规使用
- Chen Tianqi's machine learning compilation course (free)
- Use three JS realize the 'ice cream' earth, and let the earth cool for a summer
- Turn -- go deep into Lua scripting language, so that you can thoroughly understand the debugging principle
- Today's sleep quality record 71 points
- Stimulate new kinetic energy and promote digital economy in multiple places
- MySQL -- index of MyISAM storage engine
- Where can the courses purchased by CSDN be accessed
- Kubernetes create service access pod
- Genicam gentl standard ver1.5 (4) Chapter 5 acquisition engine
猜你喜欢

Configure filter

Preparation of functional test report

“信任机器”为发展赋能
![[target tracking] | single target tracking indicator](/img/07/033d5c07b07e3443330840e98940b3.png)
[target tracking] | single target tracking indicator

The fixed assets management subsystem reports are divided into what categories and which accounts are included

MySQL5.7 设置密码策略(等保三级密码改造)

Hide the creation and use of users

思科--高可用和高可靠网络考试

Turn -- go deep into Lua scripting language, so that you can thoroughly understand the debugging principle

Cutefishos system~
随机推荐
Two schemes of transforming the heat map of human posture estimation into coordinate points
Efficiency improvement - encourage personalized container development environment
Explain the use of locksupport in detail
104. SAP ui5 table control supports multi select and how to select multiple table row items at a time with code
Awoo's favorite problem (priority queue)
Use and function of spark analyze command map join broadcast join
Digital currency: far-reaching innovation
工作中非常重要的测试策略,你大概没注意过吧
rxjs Observable of 操作符的单步调试分析
Chen Tianqi's machine learning compilation course (free)
Metauniverse may become a new direction of Internet development
Pytorch nn.functional.unfold()的简单理解与用法
[literacy] deep / shallow, local / global features in machine learning image processing
Tcpdump command usage details
Demo program implementation of QT version Huarui camera
Rust language - Introduction to Xiaobai 05
Selection of all-optical technology in the park - Part 2
数字货币:影响深远的创新
【扫盲】机器学习图像处理中的深层/浅层、局部/全局特征
Mixconv code