Use os.exit(n) in Lua and the $? variable in Bash: $ lua5.1 -e 'os.exit(42)'; echo $? 42
or write all of the logic in a Lua script. ;-)