欢迎访问『www.cnblogs.com/blog-ice』

shell

错误退出

set -e

错误不退出

#!/bin/bash

command1 || { echo "command1 failed, but we'll continue"; exit 1; }
command2

 

bat

@echo off
setlocal enabledelayedexpansion

call :execute_command command1
if !errorlevel! neq 0 (
echo 第一个命令执行失败,停止执行后续命令
goto :eof
)

call :execute_command command2
goto :eof

:execute_command
%~1
exit /b %errorlevel%

posted on 2025-06-07 09:55  仙路尽头谁为峰  阅读(4)  评论(0)    收藏  举报
这里是自由发挥的天堂