EN
Bash - return values from functions
0 points
This article will show you how to return values from functions in Bash.
xxxxxxxxxx
1
2
3
my_function() {
4
result="sample value"
5
}
6
7
my_function
8
echo $result
Output:
xxxxxxxxxx
1
sample value
Note:
Remember that using global variables is not a safe solution, especially when you are creating a large project.
xxxxxxxxxx
1
2
3
my_function() {
4
local local_result="sample value"
5
echo "$local_result"
6
}
7
8
result=$(my_function)
9
echo $result
Output:
xxxxxxxxxx
1
sample value
Note:
`my_funciton`
is an alternative notation to$(my_function)
.