当前位置:网站首页>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}"
边栏推荐
- TS initial use, TS type
- Redis RDB snapshot
- 【QT】QtCreator卸载与安装(非正常状态)
- 学成在线案例实战
- . env. XXX file, with constant, but undefined
- The third part of the construction of the defense system of offensive and defensive exercises is the establishment of a practical security system
- How to display real-time 2D map after rviz is opened
- cookie、session、tooken
- jpa手写sql,用自定义实体类接收
- 【QT】Qt 使用MSVC2017找不到编译器的解决办法
猜你喜欢
Material design component - use bottomsheet to show extended content (I)
2021 robocom world robot developer competition - preliminary competition of higher vocational group
2021 RoboCom 世界机器人开发者大赛-本科组初赛
安全协议重点
有没有一段代码,让你为人类的智慧所折服
【ES实战】ES上的安全性运行方式
2021 RoboCom 世界机器人开发者大赛-高职组复赛
How to solve the image pop-up problem when pycharm calls Matplotlib to draw
Pytorch learning record
kubernetes资源对象介绍及常用命令(三)
随机推荐
Anomaly-Transformer (ICLR 2022 Spotlight)复现过程及问题
求逆序数的三个方法
ARP报文头部格式和请求流程
S32Kxxx bootloader之UDS bootloader
Write some suggestions to current and future doctoral students to sort out and share
mysql:insert ignore、insert和replace区别
使用 pair 做 unordered_map 的键值
Openwrt enable kV roaming
cookie、session、tooken
【无标题】
Key points and difficulties of the course "information content security" at Harbin Institute of Technology
在长城证券上买基金安全吗?
[LeetCode] 最后一个单词的长度【58】
SQL optimization
【CMake】Qt creator 里面的 cmake 配置
Timer和ScheduledThreadPoolExecutor的区别
多表操作-一对一,一对多与多对多
有没有一段代码,让你为人类的智慧所折服
Depth first search and breadth first search of graph traversal
Matplotlib common charts