Skip to content

Commit 9902012

Browse files
committed
docs: update NOTE comments
1 parent 9fd82c1 commit 9902012

File tree

11 files changed

+85
-45
lines changed

11 files changed

+85
-45
lines changed

bin/a2l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# @author Jerry Lee (oldratlee at gmail dot com)
1111
set -eEuo pipefail
1212

13-
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
13+
# NOTE: DO NOT declare var PROG as readonly in ONE line!
1414
PROG="$(basename "$0")"
1515
readonly PROG
1616
readonly PROG_VERSION='2.5.0-dev'

bin/ap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# @author Jerry Lee (oldratlee at gmail dot com)
1313
set -eEuo pipefail
1414

15-
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
15+
# NOTE: DO NOT declare var PROG as readonly in ONE line!
1616
PROG="$(basename "$0")"
1717
readonly PROG
1818
readonly PROG_VERSION='2.5.0-dev'

bin/c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,22 @@
1111
#
1212
# NOTE about Bash Traps and Pitfalls:
1313
#
14-
# 1. DO NOT combine var declaration and assignment which value supplied by subshell!
14+
# 1. DO NOT combine var declaration and assignment which value supplied by subshell in ONE line!
1515
# for example: readonly var1=$(echo value1)
16-
# local var1=$(echo value1)
16+
# local var2=$(echo value1)
1717
#
18-
# declaration make exit code of assignment to be always 0,
18+
# Because the combination make exit code of assignment to be always 0,
1919
# aka. the exit code of command in subshell is discarded.
2020
# tested on bash 3.2.57/4.2.46
21+
#
22+
# solution is separation of var declaration and assignment:
23+
# var1=$(echo value1)
24+
# readonly var1
25+
# local var2
26+
# var2=$(echo value1)
2127
set -eEuo pipefail
2228

23-
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
29+
# NOTE: DO NOT declare var PROG as readonly in ONE line!
2430
PROG="$(basename "$0")"
2531
readonly PROG
2632
readonly PROG_VERSION='2.5.0-dev'

bin/find-in-jars

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,22 @@
1616
#
1717
# NOTE about Bash Traps and Pitfalls:
1818
#
19-
# 1. DO NOT combine var declaration and assignment which value supplied by subshell!
19+
# 1. DO NOT combine var declaration and assignment which value supplied by subshell in ONE line!
2020
# for example: readonly var1=$(echo value1)
21-
# local var1=$(echo value1)
21+
# local var2=$(echo value1)
2222
#
23-
# declaration make exit code of assignment to be always 0,
23+
# Because the combination make exit code of assignment to be always 0,
2424
# aka. the exit code of command in subshell is discarded.
2525
# tested on bash 3.2.57/4.2.46
26+
#
27+
# solution is separation of var declaration and assignment:
28+
# var1=$(echo value1)
29+
# readonly var1
30+
# local var2
31+
# var2=$(echo value1)
2632
set -eEuo pipefail
2733

28-
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
34+
# NOTE: DO NOT declare var PROG as readonly in ONE line!
2935
PROG="$(basename "$0")"
3036
readonly PROG
3137
readonly PROG_VERSION='2.5.0-dev'
@@ -56,7 +62,7 @@ redEcho() {
5662
# Getting console width using a bash script
5763
# https://unix.stackexchange.com/questions/299067
5864
#
59-
# NOTE: DO NOT declare columns var as readonly, because its value is supplied by subshell.
65+
# NOTE: DO NOT declare columns var as readonly in ONE line!
6066
[ -t 2 ] && columns=$(stty size | awk '{print $2}')
6167

6268
printResponsiveMessage() {

bin/rp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# @author Jerry Lee (oldratlee at gmail dot com)
1313
set -eEuo pipefail
1414

15-
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
15+
# NOTE: DO NOT declare var PROG as readonly in ONE line!
1616
PROG="$(basename "$0")"
1717
readonly PROG
1818
readonly PROG_VERSION='2.5.0-dev'

bin/show-busy-java-threads

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@
1111
#
1212
# NOTE about Bash Traps and Pitfalls:
1313
#
14-
# 1. DO NOT combine var declaration and assignment which value supplied by subshell!
14+
# 1. DO NOT combine var declaration and assignment which value supplied by subshell in ONE line!
1515
# for example: readonly var1=$(echo value1)
16-
# local var1=$(echo value1)
16+
# local var2=$(echo value1)
1717
#
18-
# declaration make exit code of assignment to be always 0,
18+
# Because the combination make exit code of assignment to be always 0,
1919
# aka. the exit code of command in subshell is discarded.
2020
# tested on bash 3.2.57/4.2.46
21+
#
22+
# solution is separation of var declaration and assignment:
23+
# var1=$(echo value1)
24+
# readonly var1
25+
# local var2
26+
# var2=$(echo value1)
2127

22-
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
28+
# NOTE: DO NOT declare var PROG as readonly in ONE line!
2329
PROG="$(basename "$0")"
2430
readonly PROG
2531
readonly PROG_VERSION='2.5.0-dev'
@@ -34,7 +40,7 @@ readonly -a COMMAND_LINE=("${BASH_SOURCE[0]}" "$@")
3440
# See https://www.lifewire.com/current-linux-user-whoami-command-3867579
3541
# Because if run command by `sudo -u`, env var $USER is not rewritten/correct, just inherited from outside!
3642
#
37-
# NOTE: DO NOT declare var USER as readonly, because its value is supplied by subshell.
43+
# NOTE: DO NOT declare var USER as readonly in ONE line!
3844
USER="$(whoami)"
3945
readonly USER
4046

@@ -210,9 +216,7 @@ uname | grep '^Linux' -q || die "$PROG only support Linux, not support $(uname)
210216
# parse options
211217
################################################################################
212218

213-
# NOTE: ARGS can not be declared as readonly!!
214-
# readonly declaration make exit code of assignment to be always 0, aka. the exit code of `getopt` in subshell is discarded.
215-
# tested on bash 4.2.46
219+
# DO NOT declare var ARGS as readonly in ONE line!
216220
ARGS=$(
217221
getopt -n "$PROG" -a -o c:p:a:s:S:i:Pd:FmlhV \
218222
-l count:,pid:,append-file:,jstack-path:,store-dir:,cpu-sample-interval:,use-ps,top-delay:,force,mix-native-frames,lock-info,help,version \
@@ -363,7 +367,7 @@ readonly jstack_path
363367
# biz logic
364368
################################################################################
365369

366-
# NOTE: DO NOT declare var run_timestamp as readonly, because its value is supplied by subshell.
370+
# NOTE: DO NOT declare var run_timestamp as readonly in ONE line!
367371
run_timestamp="$(date "+%Y-%m-%d_%H:%M:%S.%N")"
368372
readonly run_timestamp
369373
readonly uuid="${PROG}_${run_timestamp}_${$}_${RANDOM}"
@@ -424,7 +428,7 @@ findBusyJavaThreadsByPs() {
424428

425429
# shellcheck disable=SC2206
426430
local -a ps_cmd_line=(ps $ps_process_select_options -wwLo 'pid,lwp,pcpu,user' --no-headers)
427-
# DO NOT combine var ps_out declaration and assignment, because its value is supplied by subshell.
431+
# DO NOT combine var ps_out declaration and assignment in ONE line!
428432
local ps_out
429433
ps_out="$("${ps_cmd_line[@]}" | sort -k3,3nr)"
430434
[ -n "$ps_out" ] || __die_when_no_java_process_found
@@ -442,7 +446,7 @@ findBusyJavaThreadsByPs() {
442446

443447
# top with output field: thread id, %cpu
444448
__top_threadId_cpu() {
445-
# DO NOT combine var java_pid_list declaration and assignment, because its value is supplied by subshell.
449+
# DO NOT combine var java_pid_list declaration and assignment in ONE line!
446450
local java_pid_list
447451
# shellcheck disable=SC2086
448452
java_pid_list="$(ps $ps_process_select_options -o pid --no-headers)"
@@ -465,14 +469,14 @@ __top_threadId_cpu() {
465469
# 4. top v3.3, there is 1 black line between 2 update;
466470
# but top v3.2, there is 2 blank lines between 2 update!
467471
local -a top_cmd_line=(top -H -b -d "$cpu_sample_interval" -n 2 -p "$java_pid_list")
468-
# DO NOT combine var ps_out declaration and assignment, because its value is supplied by subshell.
472+
# DO NOT combine var ps_out declaration and assignment in ONE line!
469473
local top_out
470474
top_out=$(HOME="$tmp_store_dir" "${top_cmd_line[@]}")
471475
if [ -n "$store_dir" ]; then
472476
echo "$top_out" | logAndCat "${top_cmd_line[@]}" >"${store_file_prefix}$((update_round_num + 1))_top"
473477
fi
474478

475-
# DO NOT combine var result_threads_top_info declaration and assignment, because its value is supplied by subshell.
479+
# DO NOT combine var result_threads_top_info declaration and assignment in ONE line!
476480
local result_threads_top_info
477481
result_threads_top_info=$(
478482
echo "$top_out" | awk '{
@@ -493,7 +497,7 @@ __complete_pid_user_by_ps() {
493497
# ps output field: pid, thread id(lwp), user
494498
# shellcheck disable=SC2206
495499
local -a ps_cmd_line=(ps $ps_process_select_options -wwLo 'pid,lwp,user' --no-headers)
496-
# DO NOT combine var ps_out declaration and assignment, because its value is supplied by subshell.
500+
# DO NOT combine var ps_out declaration and assignment in ONE line!
497501
local ps_out
498502
ps_out="$("${ps_cmd_line[@]}")"
499503
if [ -n "$store_dir" ]; then

bin/tcp-connection-state-counter

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# @author @sunuslee (sunuslee at gmail dot com)
1111
set -eEuo pipefail
1212

13-
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
13+
# NOTE: DO NOT declare var PROG as readonly in ONE line!
1414
PROG="$(basename "$0")"
1515
readonly PROG
1616
readonly PROG_VERSION='2.5.0-dev'

bin/uq

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@
1313
#
1414
# NOTE about Bash Traps and Pitfalls:
1515
#
16-
# 1. DO NOT combine var declaration and assignment which value supplied by subshell!
16+
# 1. DO NOT combine var declaration and assignment which value supplied by subshell in ONE line!
1717
# for example: readonly var1=$(echo value1)
18-
# local var1=$(echo value1)
18+
# local var2=$(echo value1)
1919
#
20-
# declaration make exit code of assignment to be always 0,
20+
# Because the combination make exit code of assignment to be always 0,
2121
# aka. the exit code of command in subshell is discarded.
2222
# tested on bash 3.2.57/4.2.46
23+
#
24+
# solution is separation of var declaration and assignment:
25+
# var1=$(echo value1)
26+
# readonly var1
27+
# local var2
28+
# var2=$(echo value1)
2329
set -eEuo pipefail
2430

25-
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
31+
# NOTE: DO NOT declare var PROG as readonly in ONE line!
2632
PROG="$(basename "$0")"
2733
readonly PROG
2834
readonly PROG_VERSION='2.5.0-dev'
@@ -205,7 +211,7 @@ done
205211
[[ $uq_opt_all_repeated == 1 && $uq_opt_repeated_method == none && ($uq_opt_count == 0 && $uq_opt_only_repeated == 0) ]] &&
206212
yellowEcho "[$PROG] WARN: -D/--all-repeated=none option without -c/-d option, just cat input simply!" >&2
207213

208-
# NOTE: DO NOT declare var uq_max_input_size as readonly, because its value is supplied by subshell.
214+
# NOTE: DO NOT declare var uq_max_input_size as readonly in ONE line!
209215
uq_max_input_size="$(convertHumanReadableSizeToSize "$uq_max_input_human_readable_size")" ||
210216
usage 2 "[$PROG] ERROR: illegal value of option -XM/--max-input: $uq_max_input_human_readable_size"
211217

bin/xpl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@
1010
#
1111
# NOTE about Bash Traps and Pitfalls:
1212
#
13-
# 1. DO NOT combine var declaration and assignment which value supplied by subshell!
13+
# 1. DO NOT combine var declaration and assignment which value supplied by subshell in ONE line!
1414
# for example: readonly var1=$(echo value1)
15-
# local var1=$(echo value1)
15+
# local var2=$(echo value1)
1616
#
17-
# declaration make exit code of assignment to be always 0,
17+
# Because the combination make exit code of assignment to be always 0,
1818
# aka. the exit code of command in subshell is discarded.
1919
# tested on bash 3.2.57/4.2.46
20+
#
21+
# solution is separation of var declaration and assignment:
22+
# var1=$(echo value1)
23+
# readonly var1
24+
# local var2
25+
# var2=$(echo value1)
2026
set -eEuo pipefail
2127

22-
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
28+
# NOTE: DO NOT declare var PROG as readonly in ONE line!
2329
PROG="$(basename "$0")"
2430
readonly PROG
2531
readonly PROG_VERSION='2.5.0-dev'

legacy-bin/cp-svn-url

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@
1111
#
1212
# NOTE about Bash Traps and Pitfalls:
1313
#
14-
# 1. DO NOT combine var declaration and assignment which value supplied by subshell!
14+
# 1. DO NOT combine var declaration and assignment which value supplied by subshell in ONE line!
1515
# for example: readonly var1=$(echo value1)
16-
# local var1=$(echo value1)
16+
# local var2=$(echo value1)
1717
#
18-
# declaration make exit code of assignment to be always 0,
18+
# Because the combination make exit code of assignment to be always 0,
1919
# aka. the exit code of command in subshell is discarded.
2020
# tested on bash 3.2.57/4.2.46
21+
#
22+
# solution is separation of var declaration and assignment:
23+
# var1=$(echo value1)
24+
# readonly var1
25+
# local var2
26+
# var2=$(echo value1)
2127

22-
# NOTE: DO NOT declare var PROG as readonly, because its value is supplied by subshell.
28+
# NOTE: DO NOT declare var PROG as readonly in ONE line!
2329
PROG="$(basename "$0")"
2430
readonly PROG_VERSION='2.5.0-dev'
2531

@@ -66,7 +72,7 @@ done
6672

6773
readonly dir="${1:-.}"
6874

69-
# NOTE: DO NOT declare var url as readonly, because its value is supplied by subshell.
75+
# NOTE: DO NOT declare var url as readonly in ONE line!
7076
url="$(svn info "${dir}" | awk '/^URL: /{print $2}')"
7177
if [ -z "${url}" ]; then
7278
echo "Fail to get svn url!" 1>&2

0 commit comments

Comments
 (0)