当前位置:网站首页>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}"
边栏推荐
- Notblank and notempty
- Deep learning | three concepts: epoch, batch, iteration
- 电商RPA机器人,助力品牌电商抢立流量高点
- The essence of software architecture
- 在长城证券上买基金安全吗?
- [understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing
- 【无标题】
- PostgreSQL source code (57) why is the performance gap so large in hot update?
- .env.xxx 文件,加了常量,却undefined
- Kubernetes resource object introduction and common commands (III)
猜你喜欢

- Oui. Env. Fichier XXX, avec constante, mais non spécifié

Concurrentskiplistmap -- principle of table skipping

Matplotlib common charts

Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS

写给当前及未来博士研究生一些建议整理分享

Why is PHP called hypertext preprocessor

Material Design组件 - 使用BottomSheet展现扩展内容(一)

ARP message header format and request flow

Kubernetes resource object introduction and common commands (III)

Redis 主从同步
随机推荐
[QT] test whether QT can connect to the database
Timer和ScheduledThreadPoolExecutor的区别
ARP报文头部格式和请求流程
Is it safe to buy funds on Great Wall Securities?
回顾数据脱敏系统
Create Ca and issue certificate through go language
2021 robocom world robot developer competition - semi finals of higher vocational group
13 MySQL-约束
Regular expression collection
Windows 7 install MySQL error: 1067
Deep learning | three concepts: epoch, batch, iteration
求逆序数的三个方法
Redis RDB snapshot
Current situation and future development trend of Internet of things
Redis RDB快照
【C#】依赖注入及Autofac
How to realize parallel replication in MySQL replication
Similarities and differences between the defined identity execution function authid determiner and PostgreSQL in Oracle
Anomaly-Transformer (ICLR 2022 Spotlight)复现过程及问题
openwrt 开启KV漫游