From 5f8a4c4d62a84751f50332cea38b58c627a77f85 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 24 Jun 2017 00:12:09 +0200 Subject: [PATCH] Fix some issues reported by shellcheck --- libexec/rbenv | 3 ++- libexec/rbenv-commands | 10 +++++----- libexec/rbenv-help | 6 ++++-- libexec/rbenv-rehash | 3 ++- libexec/rbenv-root | 2 +- libexec/rbenv-whence | 2 +- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/libexec/rbenv b/libexec/rbenv index ad5c97cb..e893220b 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -21,7 +21,8 @@ abort() { if enable -f "${BASH_SOURCE%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then abs_dirname() { - local path="$(realpath "$1")" + local path + path="$(realpath "$1")" echo "${path%/*}" } else diff --git a/libexec/rbenv-commands b/libexec/rbenv-commands index daeedd78..4c3d8456 100755 --- a/libexec/rbenv-commands +++ b/libexec/rbenv-commands @@ -28,15 +28,15 @@ shopt -s nullglob for command in "${path}/rbenv-"*; do command="${command##*rbenv-}" if [ -n "$sh" ]; then - if [ ${command:0:3} = "sh-" ]; then - echo ${command##sh-} + if [ "${command:0:3}" = "sh-" ]; then + echo "${command##sh-}" fi elif [ -n "$nosh" ]; then - if [ ${command:0:3} != "sh-" ]; then - echo ${command##sh-} + if [ "${command:0:3}" != "sh-" ]; then + echo "${command##sh-}" fi else - echo ${command##sh-} + echo "${command##sh-}" fi done done diff --git a/libexec/rbenv-help b/libexec/rbenv-help index e5013d3d..0b7e926a 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -42,6 +42,7 @@ extract_initial_comment_block() { } collect_documentation() { + # shellcheck disable=SC2016 $(type -p gawk awk | head -1) ' /^Summary:/ { summary = substr($0, 10) @@ -86,7 +87,8 @@ collect_documentation() { } documentation_for() { - local filename="$(command_path "$1")" + local filename + filename="$(command_path "$1")" if [ -n "$filename" ]; then extract_initial_comment_block < "$filename" | collect_documentation fi @@ -114,7 +116,7 @@ print_help() { eval "$(documentation_for "$command")" [ -n "$help" ] || help="$summary" - if [ -n "$usage" -o -n "$summary" ]; then + if [ -n "$usage" ] || [ -n "$summary" ]; then if [ -n "$usage" ]; then echo "$usage" else diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index ef24561a..b84de7f9 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -83,7 +83,7 @@ remove_outdated_shims() { list_executable_names() { local version file rbenv-versions --bare --skip-aliases | \ - while read version; do + while read -r version; do for file in "${RBENV_ROOT}/versions/${version}/bin/"*; do echo "${file##*/}" done @@ -136,6 +136,7 @@ shopt -s nullglob # executables. create_prototype_shim remove_outdated_shims +# shellcheck disable=SC2046 make_shims $(list_executable_names | sort -u) diff --git a/libexec/rbenv-root b/libexec/rbenv-root index 64fc90b8..42baaee8 100755 --- a/libexec/rbenv-root +++ b/libexec/rbenv-root @@ -1,3 +1,3 @@ #!/usr/bin/env bash # Summary: Display the root directory where versions and shims are kept -echo $RBENV_ROOT +echo "$RBENV_ROOT" diff --git a/libexec/rbenv-whence b/libexec/rbenv-whence index 3d4c89b4..29e08061 100755 --- a/libexec/rbenv-whence +++ b/libexec/rbenv-whence @@ -20,7 +20,7 @@ fi whence() { local command="$1" - rbenv-versions --bare | while read version; do + rbenv-versions --bare | while read -r version; do path="$(rbenv-prefix "$version")/bin/${command}" if [ -x "$path" ]; then [ "$print_paths" ] && echo "$path" || echo "$version"