I run the following:
echo "while emacs;do echo $?;done;echo Exit code: $?;" | bash
If I exit emacs through the menu or the close button, it prints exit code 0 and restarts.
If I exit emacs through typing (kill-emacs 1) ctrl-x ctrl-e
Emacs is killed and the loop is killed as well, but the exit code is still 0.
What is causing it to break out of the loop?
UPDATE: As per pqnet's advice I used single quotes instead, the code now reads:
echo 'while emacs;do echo Exit code: $?;done;echo "Exit code: $?";echo "Loop End."' | bash
This produces the same result. I assume I need to save the value of the pid within the while loop. So I try:
echo 'while epid=$(emacs);do echo Exit code: $epid;done;echo "Exit code: $epid";echo "Loop End."' | bash
If these results are to be trusted then exit code in both cases is an empty string (or invisible binary), but I don't think that's correct either? Is my asusmption of the 'return value' being an exit code an incorrect one, or just that epid is not capturing it?
UPDATE: One of the answers explained why I wasn't getting the expected results, but now I am curious to know what code would allow me to view the exit code of emacs, since none of what I've come up with does that.