当前位置:网站首页>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}"
边栏推荐
- Redis AOF log
- [untitled]
- Using SqlCommand objects in code
- kubernetes资源对象介绍及常用命令(三)
- Write some suggestions to current and future doctoral students to sort out and share
- How to realize parallel replication in MySQL replication
- [swoole Series 1] what will you learn in the world of swoole?
- E-commerce RPA robot helps brand e-commerce to achieve high traffic
- 比较通俗易懂的PID理解
- Timer和ScheduledThreadPoolExecutor的区别
猜你喜欢
. env. XXX file, with constant, but undefined
[cmake] cmake configuration in QT Creator
【CMake】Qt creator 里面的 cmake 配置
2021 robocom world robot developer competition - preliminary competition of higher vocational group
Concepts of dictionary, hash table and array
回顾数据脱敏系统
学成在线案例实战
algolia 搜索需求,做的快自闭了...
写给当前及未来博士研究生一些建议整理分享
Postgresql源码(57)HOT更新为什么性能差距那么大?
随机推荐
Pytorch learning record
E-commerce RPA robot helps brand e-commerce to achieve high traffic
Oracle中已定义者身份执行函数AUTHID DEFINER与Postgresql行为的异同
Know --matplotlib
Key points and difficulties of the course "information content security" at Harbin Institute of Technology
The best smart home open source system in 2022: introduction to Alexa, home assistant and homekit ecosystem
[QT] qtcreator uninstall and installation (abnormal state)
Which securities company is the best to open a stock account? Is there a security guarantee
Concurrentskiplistmap -- principle of table skipping
Li Kou today's question -241 Design priorities for operational expressions
[es practice] safe operation mode on ES
Material design component - use bottomsheet to show extended content (I)
2022年最佳智能家居开源系统:Alexa、Home Assistant、HomeKit生态系统介绍
const // It is a const object...class nullptr_t
回顾数据脱敏系统
How excel opens CSV files with more than one million lines
The third part of the construction of the defense system of offensive and defensive exercises is the establishment of a practical security system
攻防演练复盘
Relatively easy to understand PID understanding
2021 RoboCom 世界机器人开发者大赛-高职组初赛