From a2b9db786b2b0d782d5558f4072e841146c6e53f Mon Sep 17 00:00:00 2001 From: Dict Xiong Date: Sat, 29 Oct 2022 02:14:39 +0800 Subject: [PATCH] use local vars --- install.sh | 16 ++++++++-------- tools/common.sh | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/install.sh b/install.sh index a2fe889..904d427 100755 --- a/install.sh +++ b/install.sh @@ -13,8 +13,8 @@ crontab_job="0 * * * * ${DOTFILES}/update.sh" insert_if_not_exist() { - filename=$1 - line=$2 + local filename=$1 + local line=$2 fmt_note "installing \"$line\" into \"$filename\" ..." mkdir -p $(dirname "$filename") if [ ! -f "$filename" ]; then @@ -25,8 +25,8 @@ insert_if_not_exist() delete_if_exist() { - filename=$1 - line=$2 + local filename=$1 + local line=$2 fmt_note "removing \"$line\" from \"$filename\" ..." if [ -f "$filename" ]; then grep -vxF -- "$line" "$filename" | tee "$filename" @@ -35,8 +35,8 @@ delete_if_exist() create_symlink() { - src=$1 - dest=$2 + local src=$1 + local dest=$2 fmt_note "creating symlink \"$dest\" --> \"$src\" ..." if [ ! -f "$src" ]; then fmt_error "\"$src\" does not exist! aborting this job ..." @@ -65,8 +65,8 @@ create_symlink() delete_link_if_match() { - src=$1 - dest=$2 + local src=$1 + local dest=$2 if [ "$(readlink $dest)" -ef "$src" ]; then fmt_note "removing symlink \"$dest\" ..." echo ---------- diff --git a/tools/common.sh b/tools/common.sh index 44c9691..f3f716b 100755 --- a/tools/common.sh +++ b/tools/common.sh @@ -118,6 +118,7 @@ post_log() } get_os_type() { + local ans="unknown" case "$(uname -s)" in Darwin*) ans="MacOS";; CYGWIN*) ans="Cygwin";; @@ -129,6 +130,7 @@ get_os_type() { } get_linux_dist() { + local ans="unknown" if [ -f /etc/os-release ]; then . /etc/os-release ans="$ID"