当前位置:网站首页>Shell custom function
Shell custom function
2022-07-01 23:51:00 【Resound through heaven】
1 grammar
# Definition of function
[ function ] funname ()
{
command
[return Return value ]
}
# Call function
funname Pass parameters 1 Pass parameters 2 ...
2 demo
#!/bin/bash
fun1()
{
echo " Call parameterless function "
}
fun2()
{
echo " Find the sum of two numbers ..."
read -p " Enter the first number : " n1
read -p " Enter the second number : " n2
return $(($n1+$n2))
}
fun3()
{
echo " The first parameter is zero :${1}"
echo " The second parameter is :${2}"
return $(($1+$2))
}
# Call parameterless function
fun1
# Call return function
fun2
rs=`echo $?`
echo " The sum of two numbers is : ${rs}"
# Call the third function
fun3 2 2
rs=`echo $?`
echo "fun3 The return result is : ${rs}"
边栏推荐
- 哈工大《信息内容安全》课程知识要点和难点
- Y53. Chapter III kubernetes from introduction to mastery -- ingress (26)
- Selectively inhibiting learning bias for active sampling
- Deep learning | three concepts: epoch, batch, iteration
- 2022-07-01:某公司年会上,大家要玩一食发奖金游戏,一共有n个员工, 每个员工都有建设积分和捣乱积分, 他们需要排成一队,在队伍最前面的一定是老板
- Relatively easy to understand PID understanding
- 比较通俗易懂的PID理解
- mysql:insert ignore、insert和replace区别
- Is it safe to buy funds on Great Wall Securities?
- Algolia's search needs are almost closed
猜你喜欢
[QT] test whether QT can connect to the database
Redis AOF日志
Redis RDB快照
.env.xxx 文件,加了常量,卻undefined
TS initial use, TS type
关联性——组内相关系数
Multi table operation - one to one, one to many and many to many
字典、哈希表、数组的概念
Current situation and future development trend of Internet of things
2021 RoboCom 世界机器人开发者大赛-高职组初赛
随机推荐
2021 robocom world robot developer competition - preliminary competition of undergraduate group
SecurityUtils.getSubject().getPrincipal()为null的问题怎么解决
How to realize parallel replication in MySQL replication
[QT] qtcreator uninstall and installation (abnormal state)
Overview of edge calculation
使用uni-simple-router,动态传参 TypeError: Cannot convert undefined or null to object
[es practice] safe operation mode on ES
ADO.NET 之sqlConnection 对象使用摘要
cookie、session、tooken
安全协议重点
小程序表单校验封装
Write some suggestions to current and future doctoral students to sort out and share
Redis RDB snapshot
excel如何打开100万行以上的csv文件
2022-07-01: at the annual meeting of a company, everyone is going to play a game of giving bonuses. There are a total of N employees. Each employee has construction points and trouble points. They nee
Selectively inhibiting learning bias for active sampling
华为HMS Core携手超图为三维GIS注入新动能
Future trend and development of neural network Internet of things
Current situation and future development trend of Internet of things
Door level modeling - after class exercises