Shell 脚本失败后继续

Rog*_*des 4 bash shell

如何编写一个即使特定命令失败也能继续执行的 shell 脚本,但我想稍后输出错误,我尝试了以下方法:

#!/bin/bash
./node_modules/.bin/wdio wdio.conf.js --spec ./test/specs/login.test.js
rc=$?
echo "print here"
chown -R gitlab-runner /gpc_testes/
chown -R gitlab-runner /gpc_fontes/
exit $rc
Run Code Online (Sandbox Code Playgroud)

但是,当节点模块命令失败时,脚本会停止。

sjs*_*sam 5

你可以使用

command_that_would_fail || command_failed=1
# More code and even more
.
.
if [ ${command_failed:-0} -eq 1 ]
then
 echo "command_that_would_fail failed"
fi
Run Code Online (Sandbox Code Playgroud)