gpt4 book ai didi

bash - 如果Shell脚本中的错误不起作用,是否退出?

转载 作者:行者123 更新时间:2023-12-02 10:53:33 24 4
gpt4 key购买 nike

它编译文件并忽略所有错误。现在我要在这里的是,如果存在错误,它必须退出并停止编译

注意:我正在使用docker容器。该代码在.yml文件之后执行。如果有错误,yml将退出编译器,但在此文件中它将忽略所有错误

这是我的shell-scripts-dev.sh文件

#!/bin/bash
#do not enter current dir
#cd $(dirname $0)
BASEDIR=$(dirname "$0")
printf "\n"
printf "###############################################################################\n"
printf "# Running dev script from directory #\n"
printf "###############################################################################\n"
pwd

printf "\n"
printf "###############################################################################\n"
printf "# Create initial/ needed files #\n"
printf "###############################################################################\n"
# backend init files
if [ ! -f backend/config/main-local.php ]; then
printf "File backend/config/main-local.php does not exist, creating it, please edit configuration on server!\n"
cp backend/config/main-local.example backend/config/main-local.php
fi

if [ ! -f backend/config/params.php ]; then
printf "File backend/config/params.php does not exist, creating it, please edit configuration on server!\n"
cp backend/config/params.example backend/config/params.php
fi
if [ ! -f backend/web/index.php ]; then
printf "File backend/web/index.php does not exist, creating it, please edit configuration on server!\n"
cp backend/web/index.example backend/web/index.php
fi
if [ ! -f backend/web/index-test.php ]; then
printf "File backend/web/index-test.php does not exist, creating it, please edit configuration on server!\n"
cp backend/web/index.example backend/web/index-test.php
fi
# common init files
if [ ! -f common/config/main.php ]; then
printf "File common/config/main.php does not exist, creating it, please edit configuration on server!\n"
cp common/config/main.example common/config/main.php
fi

if [ ! -f common/config/main-local.php ]; then
printf "File common/config/main-local.php does not exist, creating it, please edit configuration on server!\n"
cp common/config/main-local.example common/config/main-local.php
fi

if [ ! -f common/config/params.php ]; then
printf "File common/config/params.php does not exist, creating it, please edit configuration on server!\n"
cp common/config/params.example common/config/params.php
fi


# rest init files
if [ ! -f rest/config/params.php ]; then
printf "File rest/config/params.php does not exist, creating it, please edit configuration on server!\n"
cp rest/config/params.example rest/config/params.php
fi
if [ ! -f rest/web/index.php ]; then
printf "File rest/web/index.php does not exist, creating it, please edit configuration on server!\n"
cp rest/web/index.example rest/web/index.php
fi
if [ ! -f rest/web/index-test.php ]; then
printf "File rest/web/index-test.php does not exist, creating it, please edit configuration on server!\n"
cp rest/web/index.example rest/web/index-test.php
fi
printf "\n"
printf "###############################################################################\n"
printf "# Clearing cache #\n"
printf "###############################################################################\n"
# backend runtime files
rm -rf backend/web/assets/*
rm -rf backend/runtime/debug/*
rm -rf backend/runtime/logs/*
rm -rf backend/runtime/mail/*
rm -rf backend/runtime/URI/*
rm -rf cache/*
# rest runtime files
rm -rf rest/runtime/cache/*
rm -rf backend/runtime/debug/*
rm -rf backend/runtime/logs/*
rm -rf backend/runtime/mail/*


###############################################################################
# Rebuild assets# - don't we need this???
###############################################################################
#chmod +x ../app/Console/cake
#cd ../app && Vendor/bin/cake asset_compress build --force

printf "\n"
printf "###############################################################################\n"
printf "# Composer update #\n"
printf "###############################################################################\n"
php composer.phar install

printf "\n"
printf "###############################################################################\n"
printf "# Running yii migrations #\n"
printf "###############################################################################\n"
yes | php yii migrate

printf "\n"
printf "###############################################################################\n"
printf "#Run PhpSniffer and output any errors #\n"
printf "###############################################################################\n"
php ./vendor/bin/phpcs --encoding=utf-8 --extensions=php backend --colors
php ./vendor/bin/phpcs --encoding=utf-8 --extensions=php common --colors
php

./vendor/bin/phpcs --encoding=utf-8 --extensions=php rest --colors

最佳答案

万一我理解正确,万一遇到错误,您需要退出bash脚本?如果是这样,您可以使用set -e命令:What does set -e mean in a bash script?

关于bash - 如果Shell脚本中的错误不起作用,是否退出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54710119/

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