如何将带有退出代码评估的 Windows 批处理文件 运行 两次 npm 转换为 Linux bash 脚本?
How to convert a Windows batch file running twice npm with exit code evaluation to a Linux bash script?
从昨天开始,我一直在尝试将 .bat 文件翻译成 bash,但没有成功,因为我对每个命令的细微之处了解不够,尤其是Windows命令call
.
@echo off
echo Installing/updating bot dependencies
call npm ci --only=production --loglevel=warn >NUL
if NOT ["%errorlevel%"]==["0"] (
pause
exit /b %errorlevel%
)
echo Starting the bot
call npm run start
if NOT ["%errorlevel%"]==["0"] (
pause
exit /b %errorlevel%
)
翻译如下:
#!/bin/bash
echo "Installing/updating bot dependencies"
npm ci --only=production --loglevel=warn >/dev/null
exit_code=$?
if [ ${exit_code} -ne 0 ]; then
read -p "Press ENTER to exit."
exit ${exit_code}
fi
echo Starting the bot
npm run start
exit_code=$?
if [ ${exit_code} -ne 0 ]; then
read -p "Press ENTER to exit."
exit ${exit_code}
fi
从昨天开始,我一直在尝试将 .bat 文件翻译成 bash,但没有成功,因为我对每个命令的细微之处了解不够,尤其是Windows命令call
.
@echo off
echo Installing/updating bot dependencies
call npm ci --only=production --loglevel=warn >NUL
if NOT ["%errorlevel%"]==["0"] (
pause
exit /b %errorlevel%
)
echo Starting the bot
call npm run start
if NOT ["%errorlevel%"]==["0"] (
pause
exit /b %errorlevel%
)
翻译如下:
#!/bin/bash
echo "Installing/updating bot dependencies"
npm ci --only=production --loglevel=warn >/dev/null
exit_code=$?
if [ ${exit_code} -ne 0 ]; then
read -p "Press ENTER to exit."
exit ${exit_code}
fi
echo Starting the bot
npm run start
exit_code=$?
if [ ${exit_code} -ne 0 ]; then
read -p "Press ENTER to exit."
exit ${exit_code}
fi