Skip to content

Commit 55ead67

Browse files
committed
bash: add checks for unset variable
1 parent 3ab13f5 commit 55ead67

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

.bashrc-support.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tk_exit_if_fail() {
2020
# $(tk_join , "${ary[@]}")
2121
# => "a,bb,ccc"
2222
tk_join() {
23-
local IFS="$1"
23+
local IFS="${1:-}"
2424
shift
2525
echo "$*"
2626
}
@@ -31,19 +31,19 @@ tk_join() {
3131
tk_trim() {
3232
# Adapted from
3333
# https://github.com/dylanaraps/pure-bash-bible#trim-leading-and-trailing-white-space-from-string
34-
local tmp=$1
34+
local tmp=${1:-}
3535
tmp=${tmp#"${tmp%%[![:space:]]*}"}
3636
tmp=${tmp%"${tmp##*[![:space:]]}"}
3737
printf '%s\n' "$tmp"
3838
}
3939

4040
tk_cmd_exist() {
41-
[[ -z $1 ]] && tk_print_error "tk_cmd_exist(): expects command name as the parameter" && return 1
41+
[[ -z ${1:-} ]] && tk_print_error "tk_cmd_exist(): expects command name as the parameter" && return 1
4242
command -v "$1" &>/dev/null
4343
}
4444

4545
tk_fn_exist() {
46-
[[ -z $1 ]] && tk_print_error "tk_fn_exist(): expects function name as the parameter" && return 1
46+
[[ -z ${1:-} ]] && tk_print_error "tk_fn_exist(): expects function name as the parameter" && return 1
4747
[[ $(type -t "$1") == "function" ]]
4848
}
4949

@@ -52,7 +52,7 @@ tk_is_login_shell() {
5252
}
5353

5454
tk_version_in_path() {
55-
[[ -z $1 ]] && tk_print_error "tk_version_in_path(): expects path as the parameter" && return 1
55+
[[ -z ${1:-} ]] && tk_print_error "tk_version_in_path(): expects path as the parameter" && return 1
5656
if [[ $1 =~ [/-]([[:digit:]]+(\.[[:digit:]]+)*) ]]; then
5757
echo "${BASH_REMATCH[1]}"
5858
fi

0 commit comments

Comments
 (0)