From 2f70e10be7bbc69944c96661fdd911d648a2b8cc Mon Sep 17 00:00:00 2001 From: whyour Date: Mon, 16 Sep 2024 21:35:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20shell=20=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=20nounset=20=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/otask.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/shell/otask.sh b/shell/otask.sh index b379b71ac8f..b73fc3dd3f1 100755 --- a/shell/otask.sh +++ b/shell/otask.sh @@ -229,6 +229,17 @@ check_file() { fi } +check_nounset() { + local output=$(set -o) + while read -r line; do + if [[ "$line" =~ "nounset" ]] && [[ "$line" =~ "on" ]]; then + set_u_on="true" + set +u + break + fi + done <<<"$output" +} + main() { if [[ $1 == *.js ]] || [[ $1 == *.py ]] || [[ $1 == *.pyc ]] || [[ $1 == *.sh ]] || [[ $1 == *.ts ]]; then if [[ $1 == *.sh ]]; then @@ -270,10 +281,7 @@ if [[ $isJsOrPythonFile == 'false' ]]; then run_task_before "${task_shell_params[@]}" fi set_u_on="false" -if set -o | grep -q 'nounset.*on'; then - set_u_on="true" - set +u -fi +check_nounset main "${task_shell_params[@]}" if [[ "$set_u_on" == 'true' ]]; then set -u