From e58a4aea3bd71f991d08594882daa6eee0944ded Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Thu, 16 Nov 2023 01:10:26 +0800 Subject: [PATCH] refactor: use file descriptor number instead of `/dev/std*`; move var location --- bin/ap | 7 +++---- bin/c | 7 +++---- bin/cp-into-docker-run | 7 +++---- bin/find-in-jars | 12 ++++++------ bin/rp | 7 +++---- bin/show-busy-java-threads | 7 +++---- bin/uq | 7 +++---- bin/xpl | 7 +++---- test-cases/bump-scripts-version.sh | 2 +- 9 files changed, 28 insertions(+), 35 deletions(-) diff --git a/bin/ap b/bin/ap index 1c598985..355163dc 100755 --- a/bin/ap +++ b/bin/ap @@ -73,14 +73,13 @@ portableReadLink() { usage() { local -r exit_code="${1:-0}" (($# > 0)) && shift - # shellcheck disable=SC2015 - [ "$exit_code" != 0 ] && local -r out=/dev/stderr || local -r out=/dev/stdout + local -r out=$(((exit_code != 0) + 1)) # NOTE: $'foo' is the escape sequence syntax of bash local nl=$'\n' # new line - (($# > 0)) && redPrint "$*$nl" >"$out" + (($# > 0)) && redPrint "$*$nl" >&"$out" - cat >"$out" <&"$out" < 0)) && shift - # shellcheck disable=SC2015 - [ "$exit_code" != 0 ] && local -r out=/dev/stderr || local -r out=/dev/stdout + local -r out=$(((exit_code != 0) + 1)) - (($# > 0)) && printErrorMsg "$*" >"$out" + (($# > 0)) && printErrorMsg "$*" >&"$out" - cat >"$out" <&"$out" < 0)) && shift - # shellcheck disable=SC2015 - [ "$exit_code" != 0 ] && local -r out=/dev/stderr || local -r out=/dev/stdout + local -r out=$(((exit_code != 0) + 1)) # NOTE: $'foo' is the escape sequence syntax of bash local nl=$'\n' # new line - (($# > 0)) && redPrint "$*$nl" >"$out" + (($# > 0)) && redPrint "$*$nl" >&"$out" - cat >"$out" <&"$out" < 0)) && shift - # shellcheck disable=SC2015 - [ "$exit_code" != 0 ] && local -r out=/dev/stderr || local -r out=/dev/stdout + local -r out=$(((exit_code != 0) + 1)) # NOTE: $'foo' is the escape sequence syntax of bash local -r nl=$'\n' # new line - (($# > 0)) && redPrint "$*$nl" >"$out" + (($# > 0)) && redPrint "$*$nl" >&"$out" - cat >"$out" <&"$out" < 0)) && shift - # shellcheck disable=SC2015 - [ "$exit_code" != 0 ] && local -r out=/dev/stderr || local -r out=/dev/stdout + local -r out=$(((exit_code != 0) + 1)) # NOTE: $'foo' is the escape sequence syntax of bash local nl=$'\n' # new line - (($# > 0)) && redPrint "$*$nl" >"$out" + (($# > 0)) && redPrint "$*$nl" >&"$out" - cat >"$out" <&"$out" < 0)) && shift - # shellcheck disable=SC2015 - [ "$exit_code" != 0 ] && local -r out=/dev/stderr || local -r out=/dev/stdout + local -r out=$(((exit_code != 0) + 1)) - (($# > 0)) && colorPrint 31 "$*$nl" >"$out" + (($# > 0)) && colorPrint 31 "$*$nl" >&"$out" - cat >"$out" <&"$out" < 0)) && shift - # shellcheck disable=SC2015 - [ "$exit_code" != 0 ] && local -r out=/dev/stderr || local -r out=/dev/stdout + local -r out=$(((exit_code != 0) + 1)) - (($# > 0)) && redPrint "$*$nl" >"$out" + (($# > 0)) && redPrint "$*$nl" >&"$out" - cat >"$out" <&"$out" < 0)) && shift - # shellcheck disable=SC2015 - [ "$exit_code" != 0 ] && local -r out=/dev/stderr || local -r out=/dev/stdout + local -r out=$(((exit_code != 0) + 1)) - (($# > 0)) && printf '%s\n\n' "$*" >"$out" + (($# > 0)) && printf '%s\n\n' "$*" >&"$out" - cat <&"$out" <