In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to solve the problem of function return value exceeding in Shell". In daily operation, I believe many people have doubts about how to solve the problem of function return value exceeding in Shell. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for everyone to solve the problem of "how to solve the problem of function return value exceeding in Shell". Next, please follow the editor to study!
Introduction to shell function
Syntax:
The code is as follows:
[function] funname [()]
{
Action
[return int;]
}
Description:
(1) it can be defined with function fun () or directly fun () without any parameters.
(2) if the parameter is returned, you can display the plus: return return. If you do not add it, the result will be run with the last command as the return value. Return is followed by the value n (0-255) and can also be returned directly through echo.
Be careful
In shell, the return through return is limited, with a maximum of 255.If it exceeds 255, the calculation starts at 0.
Today, I made this mistake at work, resulting in the incorrect value of the output, and the bug was raised by the test department.
Example of shell script call:
The code is as follows:
#! / bin/sh
Echo "shell function operation"
Func1 ()
{
Local num1=100
Local num2=100
Let sum=$num1+$num2
Return $sum
}
Func2 ()
{
Local num1=100
Local num2=155
Let sum=$num1+$num2
Return $sum
}
Func3 ()
{
Local num1=100
Local num2=156
Let sum=$num1+$num2
Return $sum
}
Func4 ()
{
Local num1=100
Local num2=156
Let sum=$num1+$num2
Echo $sum
}
Func1
Echo "called func1:$?"
Func2
Echo "called func2:$?"
Func3
Echo "called func3:$?"
Sum= `func4`
Echo "called func4:$sum"
The execution result is as follows:
At this point, the study on "how to solve the problem of function return value exceeding in Shell" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.