8/14/2023 0 Comments Clean exit![]() $ sh -c 'sh -c "exit 1" || exit 1' echo $? 1 # the OR _was_ used ![]() You can see the results here: $ sh -c 'sh -c "exit 0" || exit 1' echo $? 0 # the OR was not used So || (or) reads as: if it failed then do X. Except in exit codes, remember, 0 is success (truthy), and 1 is failure ( falsy). If you've used to an or statement in code then you (like me) might think that exit 0 || exit 1 would result in 1 - since 0 is generally falsy. Now if mocha fails with exit 2 it'll exit nodemon's exec with an exit 1 which nodemon sees as a failure. When I run mocha inside of nodemon, I use an bash or statement that reads "if this fails, fail with an exit 1": $ nodemon -exec "mocha || exit 1" The "fix" is only a few characters though. This is a weirdness of mocha that (misuses) the exit status reporting the number of failing tests. When I ran mocha, it was returning an exit code of 2. Then the shell value $? is the numerical status of the exit code from the last executed command. ![]() Running sh -c "…" runs the string as a bash command and returns the result. But to test this, you can run the following: $ sh -c "exit 0" If you try this in your terminal, the terminal will just close (since you're running exit). There's only a handful of standardised exit codes, but the ones of most interest are: When a process runs (in a unix-based system…I'm unsure how much applies to Windows), it will exit with a code. I've published 38 videos for new developers, designers, UX, UI, product owners and anyone who needs to conquer the command line today. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |