Skip to content

Commit a982202

Browse files
committed
refactor: extract UNAME var 🔠
1 parent e3533a0 commit a982202

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

bin/show-busy-java-threads

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ readonly -a COMMAND_LINE=("${BASH_SOURCE[0]}" "$@")
2222
# $USER may be overwritten; if run command by `sudo -u`, may is not `root`.
2323
# more info see https://www.baeldung.com/linux/get-current-user
2424
#
25-
# DO NOT declare and assign var WHOAMI(as readonly) in ONE line!
25+
# DO NOT declare and assign var(as readonly) in ONE line!
2626
# more info see https://github.com/koalaman/shellcheck/wiki/SC2155
2727
WHOAMI=$(whoami)
28-
readonly WHOAMI
28+
UNAME=$(uname)
29+
readonly WHOAMI UNAME
2930

3031
################################################################################
3132
# util functions
@@ -196,10 +197,10 @@ progVersion() {
196197
}
197198

198199
################################################################################
199-
# Check os support
200+
# check os support
200201
################################################################################
201202

202-
uname | grep '^Linux' -q || die "$PROG only support Linux, not support $(uname) yet!"
203+
[[ $UNAME = Linux* ]] || die "$PROG only support Linux, not support $UNAME yet!"
203204

204205
################################################################################
205206
# parse options
@@ -565,10 +566,6 @@ printStackOfThreads() {
565566
done
566567
}
567568

568-
################################################################################
569-
# Main
570-
################################################################################
571-
572569
main() {
573570
local update_round_num
574571
# if update_count <= 0, infinite loop till user interrupted (eg: CTRL+C)

bin/tcp-connection-state-counter

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ unset args idx
5050
################################################################################
5151

5252
# On MacOS, netstat need to using -p tcp to get only tcp output.
53-
uname | grep Darwin -q && option_for_mac=-ptcp
53+
UNAME=$(uname)
54+
[[ $UNAME = Darwin* ]] && option_for_mac=-ptcp
5455

5556
# shellcheck disable=SC2086
5657
netstat -tna ${option_for_mac:-} | awk 'NR > 2 {

0 commit comments

Comments
 (0)