With a Python function in testreturn.py defined as:
import sys
def main():
sys.exit(1)
When called from a bash function in scrip.sh defined as:
#!/bin/bash
function test()
{
python testreturn.py
echo $?
}
Why does the following command:
test
0
I would like the bash function to print the exit code of the python script.
Because you're defining, but never calling the main() function. The code finishes as normal (by reaching the end of the file) and return code is 0 in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With