gpt4 book ai didi

bash - Shell脚本失败后继续

转载 作者:行者123 更新时间:2023-12-05 07:42:11 27 4
gpt4 key购买 nike

如何编写一个 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

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

最佳答案

你可以使用

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

关于bash - Shell脚本失败后继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44707925/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com