When a script exits with sys.exit(N) where N != 0, the exit code of the process is N. This allows the script to set the exit code.
However, when such a script is run using "ipython -c", all such exit codes get turned into 1. For example:
$ python -c "import sys;sys.exit(2)"; echo $?
2
$ ipython -c "import sys;sys.exit(2)"; echo $?
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
/home/abeld/.virtualenvs/ipython_bugtest/lib/python3.10/site-packages/IPython/core/interactiveshell.py:3587: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
1
$
Note that the "echo $?" prints "1" instead of "2".
(tested using ipython version 8.38.0)
This appears to be due to having a self.exit(1) in shellapp.py, which forces all these exit codes to 1: