Skip to content

Commit

Permalink
修复 shell 检查 nounset 变量
Browse files Browse the repository at this point in the history
  • Loading branch information
whyour committed Sep 16, 2024
1 parent 66706ce commit 2f70e10
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions shell/otask.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2f70e10

Please sign in to comment.