Skip to content

Commit ebb62cd

Browse files
committed
refactor: use shellcheck item doc link instead of prolixity comments ✨
1 parent 7e03b4f commit ebb62cd

File tree

7 files changed

+11
-121
lines changed

7 files changed

+11
-121
lines changed

bin/c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@
88
#
99
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/shell.md#-c
1010
# @author Jerry Lee (oldratlee at gmail dot com)
11-
#
12-
# NOTE about Bash Traps and Pitfalls:
13-
#
14-
# 1. DO NOT combine var declaration and assignment which value supplied by subshell in ONE line!
15-
# for example: readonly var1=$(echo value1)
16-
# local var2=$(echo value1)
17-
#
18-
# Because the combination make exit code of assignment to be always 0,
19-
# aka. the exit code of command in subshell is discarded.
20-
# 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)
2711
set -eEuo pipefail
2812

2913
readonly PROG=${0##*/}

bin/find-in-jars

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,6 @@
1313
#
1414
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/java.md#-find-in-jars
1515
# @author Jerry Lee (oldratlee at gmail dot com)
16-
#
17-
# NOTE about Bash Traps and Pitfalls:
18-
#
19-
# 1. DO NOT combine var declaration and assignment which value supplied by subshell in ONE line!
20-
# for example: readonly var1=$(echo value1)
21-
# local var2=$(echo value1)
22-
#
23-
# Because the combination make exit code of assignment to be always 0,
24-
# aka. the exit code of command in subshell is discarded.
25-
# 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)
3216
set -eEuo pipefail
3317

3418
readonly PROG=${0##*/}
@@ -63,8 +47,6 @@ readonly LINE_CLEAR='\e[2K\r'
6347

6448
# Getting console width using a bash script
6549
# https://unix.stackexchange.com/questions/299067
66-
#
67-
# NOTE: DO NOT declare columns var as readonly in ONE line!
6850
[ -t 2 ] && COLUMNS=$(stty size | awk '{print $2}')
6951

7052
printResponsiveMessage() {

bin/show-busy-java-threads

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@
88
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/java.md#-show-busy-java-threads
99
# @author Jerry Lee (oldratlee at gmail dot com)
1010
# @author superhj1987 (superhj1987 at 126 dot com)
11-
#
12-
# NOTE about Bash Traps and Pitfalls:
13-
#
14-
# 1. DO NOT combine var declaration and assignment which value supplied by subshell in ONE line!
15-
# for example: readonly var1=$(echo value1)
16-
# local var2=$(echo value1)
17-
#
18-
# Because the combination make exit code of assignment to be always 0,
19-
# aka. the exit code of command in subshell is discarded.
20-
# 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)
2711

2812
readonly PROG=${0##*/}
2913
readonly PROG_VERSION='2.x-dev'
@@ -38,7 +22,8 @@ readonly -a COMMAND_LINE=("${BASH_SOURCE[0]}" "$@")
3822
# See https://www.lifewire.com/current-linux-user-whoami-command-3867579
3923
# Because if run command by `sudo -u`, env var $USER is not rewritten/correct, just inherited from outside!
4024
#
41-
# NOTE: DO NOT declare var USER as readonly in ONE line!
25+
# DO NOT declare and assign var USER(as readonly) in ONE line!
26+
# more info see https://github.com/koalaman/shellcheck/wiki/SC2155
4227
USER=$(whoami)
4328
readonly USER
4429

@@ -220,7 +205,7 @@ uname | grep '^Linux' -q || die "$PROG only support Linux, not support $(uname)
220205
# parse options
221206
################################################################################
222207

223-
# DO NOT declare var ARGS as readonly in ONE line!
208+
# DO NOT declare and assign var ARGS(as readonly) in ONE line!
224209
ARGS=$(
225210
getopt -n "$PROG" -a -o c:p:a:s:S:i:Pd:FmlhV \
226211
-l count:,pid:,append-file:,jstack-path:,store-dir:,cpu-sample-interval:,use-ps,top-delay:,force,mix-native-frames,lock-info,help,version \
@@ -371,7 +356,7 @@ readonly jstack_path
371356
# biz logic
372357
################################################################################
373358

374-
# NOTE: DO NOT declare var run_timestamp as readonly in ONE line!
359+
# DO NOT declare and assign var run_timestamp(as readonly) in ONE line!
375360
run_timestamp=$(date "+%Y-%m-%d_%H:%M:%S.%N")
376361
readonly run_timestamp
377362
readonly uuid="${PROG}_${run_timestamp}_${$}_${RANDOM}"
@@ -433,6 +418,7 @@ findBusyJavaThreadsByPs() {
433418
# shellcheck disable=SC2206
434419
local -a ps_cmd_line=(ps $ps_process_select_options -wwLo 'pid,lwp,pcpu,user' --no-headers)
435420
# DO NOT combine var ps_out declaration and assignment in ONE line!
421+
# more info see https://github.com/koalaman/shellcheck/wiki/SC2155
436422
local ps_out
437423
ps_out=$("${ps_cmd_line[@]}" | sort -k3,3nr)
438424
[ -n "$ps_out" ] || __die_when_no_java_process_found
@@ -473,7 +459,7 @@ __top_threadId_cpu() {
473459
# 4. top v3.3, there is 1 black line between 2 update;
474460
# but top v3.2, there is 2 blank lines between 2 update!
475461
local -a top_cmd_line=(top -H -b -d "$cpu_sample_interval" -n 2 -p "$java_pid_list")
476-
# DO NOT combine var ps_out declaration and assignment in ONE line!
462+
# DO NOT combine var top_out declaration and assignment in ONE line!
477463
local top_out
478464
top_out=$(HOME=$tmp_store_dir "${top_cmd_line[@]}")
479465
if [ -n "$store_dir" ]; then

bin/uq

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,6 @@
1010
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/shell.md#-uq
1111
# @author Zava Xu (zava.kid at gmail dot com)
1212
# @author Jerry Lee (oldratlee at gmail dot com)
13-
#
14-
# NOTE about Bash Traps and Pitfalls:
15-
#
16-
# 1. DO NOT combine var declaration and assignment which value supplied by subshell in ONE line!
17-
# for example: readonly var1=$(echo value1)
18-
# local var2=$(echo value1)
19-
#
20-
# Because the combination make exit code of assignment to be always 0,
21-
# aka. the exit code of command in subshell is discarded.
22-
# 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)
2913
set -eEuo pipefail
3014

3115
readonly PROG=${0##*/}
@@ -217,11 +201,12 @@ done
217201
[[ $uq_opt_all_repeated == 1 && $uq_opt_repeated_method == none && ($uq_opt_count == 0 && $uq_opt_only_repeated == 0) ]] &&
218202
yellowPrint "[$PROG] WARN: -D/--all-repeated=none option without -c/-d option, just cat input simply!" >&2
219203

220-
# NOTE: DO NOT declare var uq_max_input_size as readonly in ONE line!
204+
# DO NOT declare and assign var uq_max_input_size(as readonly) in ONE line!
205+
# more info see https://github.com/koalaman/shellcheck/wiki/SC2155
221206
uq_max_input_size=$(convertHumanReadableSizeToSize "$uq_max_input_human_readable_size") ||
222207
usage 2 "[$PROG] ERROR: illegal value of option -XM/--max-input: $uq_max_input_human_readable_size"
223208

224-
readonly argc=${#argv[@]} argv
209+
readonly argc=${#argv[@]} argv uq_max_input_size
225210

226211
if ((argc == 0)); then
227212
input_files=()

bin/xpl

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,6 @@
77
#
88
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/shell.md#-xpl-and-xpf
99
# @author Jerry Lee (oldratlee at gmail dot com)
10-
#
11-
# NOTE about Bash Traps and Pitfalls:
12-
#
13-
# 1. DO NOT combine var declaration and assignment which value supplied by subshell in ONE line!
14-
# for example: readonly var1=$(echo value1)
15-
# local var2=$(echo value1)
16-
#
17-
# Because the combination make exit code of assignment to be always 0,
18-
# aka. the exit code of command in subshell is discarded.
19-
# 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)
2610
set -eEuo pipefail
2711

2812
readonly PROG=${0##*/}

legacy-bin/cp-svn-url

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@
88
#
99
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/vcs.md#-cp-svn-url
1010
# @author ivanzhangwb (ivanzhangwb at gmail dot com)
11-
#
12-
# NOTE about Bash Traps and Pitfalls:
13-
#
14-
# 1. DO NOT combine var declaration and assignment which value supplied by subshell in ONE line!
15-
# for example: readonly var1=$(echo value1)
16-
# local var2=$(echo value1)
17-
#
18-
# Because the combination make exit code of assignment to be always 0,
19-
# aka. the exit code of command in subshell is discarded.
20-
# 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)
2711

2812
readonly PROG=${0##*/}
2913
readonly PROG_VERSION='2.x-dev'
@@ -74,7 +58,8 @@ done
7458

7559
readonly dir="${1:-.}"
7660

77-
# NOTE: DO NOT declare var url as readonly in ONE line!
61+
# DO NOT declare and assign var url(as readonly) in ONE line!
62+
# more info see https://github.com/koalaman/shellcheck/wiki/SC2155
7863
url="$(svn info "${dir}" | awk '/^URL: /{print $2}')"
7964
if [ -z "${url}" ]; then
8065
echo "Fail to get svn url!" >&2

lib/console-text-color-themes.sh

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,6 @@
44
#
55
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/shell.md#-console-text-color-themessh
66
# @author Jerry Lee (oldratlee at gmail dot com)
7-
#
8-
# NOTE about Bash Traps and Pitfalls:
9-
#
10-
# 1. DO NOT combine var declaration and assignment which value supplied by subshell in ONE line!
11-
# for example: readonly var1=$(echo value1)
12-
# local var2=$(echo value1)
13-
#
14-
# Because the combination make exit code of assignment to be always 0,
15-
# aka. the exit code of command in subshell is discarded.
16-
# tested on bash 3.2.57/4.2.46
17-
#
18-
# solution is separation of var declaration and assignment:
19-
# var1=$(echo value1)
20-
# readonly var1
21-
# local var2
22-
# var2=$(echo value1)
237

248
colorEcho() {
259
local combination=$1

0 commit comments

Comments
 (0)