Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script to return exit code from NodeJs script

I have a Bash script which runs a node script as part of its tasks. I would like the bash script to exit with the same exit code as the node script. Simplified example below.

foo.sh:

#!/bin/bash
node ./bar.js

bar.js:

process.exit(1); //sometimes the exit code can be 0
like image 722
Andrew Avatar asked Jun 17 '15 02:06

Andrew


1 Answers

From: http://www.tldp.org/LDP/abs/html/exit-status.html

When a script ends with an exit that has no parameter, the exit status of the script is the exit status of the last command executed in the script

which implies that you simply need to add "exit" to your above script.

#!/bin/bash
node ./bar.js
exit
like image 164
EJK Avatar answered Oct 05 '22 23:10

EJK