当前位置:网站首页>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}"
边栏推荐
猜你喜欢
104. SAP ui5 table control supports multi select and how to select multiple table row items at a time with code
Explain the use of locksupport in detail
Daily question brushing record (10)
Understanding of transactions in MySQL
今日睡眠质量记录71分
使用3DMax制作一个象棋棋子
Digital currency: far-reaching innovation
Hide the creation and use of users
SAP GUI 里的收藏夹事务码管理工具
ESP自动下载电路设计
随机推荐
Today's sleep quality record 71 points
leetcode - 287. Find duplicates
今日睡眠质量记录71分
Mixconv code
Pytorch nn.functional.unfold()的简单理解与用法
轉載csdn文章操作
Cloud Vulnerability Global Database
Turn -- use setjmp and longjmp in C language to realize exception capture and collaboration
Yolov5.5 call local camera
mixconv代码
转--原来gdb的底层调试原理这么简单
力扣 710. 黑名单中的随机数
死锁的处理策略—预防死锁、避免死锁、检测和解除死锁
Use and function of spark analyze command map join broadcast join
数字货币:影响深远的创新
Réimpression de l'article csdn
Single step debugging analysis of rxjs observable of operator
Introduction and use of plantuml
Vsphere+ and vsan+ are coming! VMware hybrid cloud focus: native, fast migration, mixed load
Niuke monthly race - logarithmic sum in groups