Skip to content

Instantly share code, notes, and snippets.

@webknjaz
Last active October 13, 2016 09:35
Show Gist options
  • Save webknjaz/b59aa9010fc76b229cf6a5233b3a895d to your computer and use it in GitHub Desktop.
Save webknjaz/b59aa9010fc76b229cf6a5233b3a895d to your computer and use it in GitHub Desktop.
POSIX return code processing example
#! /usr/bin/env python
import sys
def main():
arg = sys.argv[1]
if smth_went_wrong(arg):
return 1 # failure code
return 0 # POSIX success
sys.exit(main())
# http://tldp.org/LDP/abs/html/comparison-ops.html
arg=`cat $1`
# case 1
python script.py "$arg"
retcode=$?
if [ $retcode -eq 1 ]; then
# "==" is a string comparison, not integer
exit 0
fi
# case 2
python script.py "$arg" || exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment