as the title of the question, here is the scenario.
A shell script file script.sh
that does some operations and at some point it requires to launch a node file.
#! /bin/bash
node "$(dirname "$0")/script.js" "$input"
echo "${?}\n"
In the node file script.js
there are some controls and in case of error the script return with an error exit code.
process.exit(1)
Is it possible to catch this error exit code in order to let the command to be executed in the shell script script.sh
?
Currently the execution is interrupted with this error error Command failed with exit code 1.
, as expected by the way.
But I would like to know if I can on shell script to catch this error and continue to execute the last part of the code echo "${?}\n"
.
Thanks in advance
You can do something like this in your bash script in case your node script return 1
node "$(dirname "$0")/script.js" "$input"
echo "Script: $? - Successfull"
if [ $? != 0 ]; then
echo "${?}\n". 1>&2 && exit 1
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With