Return Values and Status
return gives an exit status 0 to 255. Use it for success and failure checks.
Example
is_even() { (( $1 % 2 == 0 )); }
if is_even 4; then echo "4 even"; fi
is_even 7 || echo "7 odd"
f() { return 3; }
f; echo "code $?"Result
4 even 7 odd code 3
Exercise
Exit a function.
0Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.