【发布时间】:2021-10-31 00:55:19
【问题描述】:
如何从嵌套的 shell 脚本中抛出错误并使父 shell 脚本也停止?
我有这个 shell 脚本 (a.sh)
#!/bin/bash
echo "Testing if SDK build config is correct"
FILE="App/env/index.tsx"
CONST_TO_CHECK='[a-zA-Z_]*'
RED=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
if grep -Eq 'export\s*const\s*'${CONST_TO_CHECK}'\s*=\s*false' "$FILE"; then
echo "${RED}Error: All values should be true for sdk build in env.ts file${reset}"
exit 1
fi
echo "${green}Build config seems correct${reset}"
我从b.sh 运行。如果a.sh 抛出错误,我也想在 b.sh 中停止进一步执行。
我正在从 a.sh 调用 b.sh。
认为这是我的b.sh
#!/bin/bash
sh ./a.sh
rm -rf ios/ios-sdk/out/Frameworks
xcodebuild clean \
-workspace ios/dyteClientMobile.xcworkspace \
-scheme DyteSdk
更多代码
【问题讨论】: