Junior — Middle
What is the result of the function execution in the Bash script?
sobes.tech AI
Answer from AI
In Bash, a function returns an exit code (an integer from 0 to 255), which can be used to check for successful execution. To pass data from a function, output via echo or modification of global variables are usually used.
Example:
my_function() {
echo "Result of the function"
return 0 # successful exit code
}
result=$(my_function)
echo "Function returned: $result"
Here, return sets the exit code, and echo outputs the result, which can be saved in a variable.