当前位置:网站首页>(8) Shell function
(8) Shell function
2022-07-27 11:22:00 【Hungry Taibai Xingjun】
#!/bin/bash
# 1. Shell function
# 1.1 Function definition format
:<<EOF
[ function ] funcname [()]
{
action;
[return int;]
}
# 1. You can take function fun() Definition , It can also be direct fun() Definition , Without any parameters
# 2. Parameter return , Can display plus :return return , If not , The result of the last command will be returned as a result .
# 3. return Rear root value n(0-255)
EOF
# 1.2 example 1
demoFun()
{
echo " This is my first Shell function "
}
echo "-------- The function starts executing --------"
demoFun
echo "-------- End of function execution --------"
# 1.3 example 2( belt return sentence )
funWithReturn()
{
echo " Enter a number "
read aNum
echo " The number you enter is ${aNum}"
return ${
aNum}
}
funWithReturn
echo "funWithReturn The return value is $? !" # The return value of the function passes through $? To obtain a .
# Function must be defined first , After the call
# 1. Function parameter
# Inside the body of the function , adopt $n To get the value of the parameter , for example ,$1 Represents the first parameter ,$2 Represents the second parameter ...
funWithParam()
{
echo " The first 1 The parameter is $1 !"
echo " The first 2 The parameter is $2 !"
echo " The first 3 The parameter is $3 !"
echo " The eleventh parameter is ${11} !" # Be careful ,$10 Can't get the tenth parameter , Getting the tenth parameter requires ${10}. When n>=10 when , Need to use ${n} To get the parameters .
echo " The total number of parameters is $# individual !"
echo " Output all parameters as a string $* !"
}
funWithParam 1 2 3 4 5 6 7 8 9 34 73
:<<EOF
$# Number of arguments passed to script or function
$* Display all the parameters passed to the script in a single string
$$ The current process the script runs ID Number
$! Of the last process running in the background ID Number
[email protected] And $* identical , But use quotation marks , And return each parameter in quotation marks .
$- Show Shell Current options used , And set Same command function .
$? Display the exit status of the last command .0 No mistakes , Any other value indicates an error .
EOF
边栏推荐
- [FPGA tutorial case 40] communication case 10 -- Verilog implementation of a simple OFDM system based on FPGA
- 2022 Niuke multi school training (3) a-ancestor topic translation
- tensorflow运行报错解决方法
- 高斯消元 AcWing 883. 高斯消元解线性方程组
- Error while unzipping file in win10: unable to create symbolic link. You may need to run WinRAR with administrator privileges. The client does not have the required privileges
- 数字三角形模型 AcWing 1027. 方格取数
- Redis high availability principle
- Digital triangle model acwing 275. pass note
- Sorry, you guys have something to deal with in the bank recently, which has been delayed
- Data assets are king. How to analyze the relationship between enterprise digital transformation and data asset management?
猜你喜欢

XXX packages are looking for funding run 'NPM fund' for details solutions

求组合数 AcWing 889. 满足条件的01序列

Knapsack model acwing 1024. Packing problem
![[shader realizes shake random shaking effect _shader effect Chapter 10]](/img/49/99669ebc3ba59a0277bb8bc928f576.png)
[shader realizes shake random shaking effect _shader effect Chapter 10]

数字三角形模型 AcWing 1027. 方格取数

Backpack model acwing 1022. Collection of pet elves

状态压缩DP AcWing 91. 最短Hamilton路径

Yiwen counts NFT projects valued at more than US $100million

SQL Server2000 database error

15 design movie rental system
随机推荐
How to build a real-time development platform to deeply release the value of enterprise real-time data?
49字母异位分组和242有效的字母异位词
Win10 vscode code code format setting and remote breakpoint debugging
Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing
Backpack model acwing 1022. Collection of pet elves
力扣——10. 正则表达式匹配
Longest ascending subsequence model acwing 1012. Sister Cities
An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft
Game theory acwing 892. Step Nim game
Instructions for mock platform
Knapsack problem acwing 9. grouping knapsack problem
数字三角形模型 AcWing 1027. 方格取数
01 BTC cryptology principle
What is the issuing price of NFT (Interpretation of NFT and establishment of NFT world outlook)
Kangaroo cloud stack based on CBO in spark SQL optimization
Cancer DDD
IO stream_ Character stream, IO stream summary, IO stream case summary
基于FPGA的ECG信号采集,存储以及传输系统verilog实现
Yiwen counts NFT projects valued at more than US $100million
KEPServer配置