From 0877d9f169e590d9f57ec7b67b4433dc1aa9c559 Mon Sep 17 00:00:00 2001 From: SpicyCat Date: Sun, 15 Jul 2018 22:18:17 +0800 Subject: [PATCH] Wrap $(cmd_version xxxx) with double quotes cmd_version xxxx like cmd_version hledger will return empty string if hledger is not installed, and then `cmpver $(cmd_version hledger) $HLEDGER_VERSION` will become `cmpver $HLEDGER_VERSION` Wrapping $(cmd_version xxxx) with double quotes can solve this. --- hledger-install/hledger-install.sh | 48 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/hledger-install/hledger-install.sh b/hledger-install/hledger-install.sh index 4570f49d3..424662a41 100755 --- a/hledger-install/hledger-install.sh +++ b/hledger-install/hledger-install.sh @@ -1,6 +1,6 @@ #!/bin/bash # Easy hledger installation script for POSIX systems. -# Uses cabal if installed and stack is not, +# Uses cabal if installed and stack is not, # or stack, which it will install if needed (or if --force-install-stack is used). # Requires bash and some other POSIX tools. # This is based on get-stack.sh which is copyright (c) 2015-2017, Stack contributors. @@ -12,15 +12,15 @@ usage() { cat </dev/null | grep -E '[0-9]' | $SED -e 's/[^0-9]*([0-9][0-9.]*).*/\1/') || "" @@ -778,7 +778,7 @@ cmd_version() { # Check whether the given command exists with given version has_cmd_version() { - [[ $(cmd_version "$1") == "$2" ]] + [[ $(cmd_version "$1") == "$2" ]] } # Show a command's presence in $PATH, and its version if present. @@ -790,7 +790,7 @@ print_cmd_version() { fi } -# Show the installation status of the $HLEDGER_MAIN_TOOLS and $HLEDGER_OTHER_TOOLS. +# Show the installation status of the $HLEDGER_MAIN_TOOLS and $HLEDGER_OTHER_TOOLS. print_hledger_versions() { for cmd in $HLEDGER_MAIN_TOOLS $HLEDGER_OTHER_TOOLS $HLEDGER_INSTALL_TOOL ; do print_cmd_version "$cmd"; done } @@ -806,7 +806,7 @@ quietly_run() { "$@" 2>/dev/null || true } -# Try to install the executables of the given package(s) to $HOME/.local/bin, +# Try to install the executables of the given package(s) to $HOME/.local/bin, # trying several methods, generally from quickest to most reliable, continuing on failure. # Current the installation methods are: # - if stack is not installed and cabal is, try cabal install @@ -949,13 +949,13 @@ cmpver () { # try installing each package that needs installing, in turn echo ---------- -if [[ $(cmpver $(cmd_version hledger) $HLEDGER_VERSION) = 2 ]]; then +if [[ $(cmpver "$(cmd_version hledger)" $HLEDGER_VERSION) = 2 ]]; then echo Installing hledger try_install hledger-$HLEDGER_VERSION hledger-lib-$HLEDGER_LIB_VERSION echo fi -if [[ $(cmpver $(cmd_version hledger-ui) $HLEDGER_UI_VERSION) = 2 ]]; then +if [[ $(cmpver "$(cmd_version hledger-ui)" $HLEDGER_UI_VERSION) = 2 ]]; then echo Installing hledger-ui try_install hledger-ui-$HLEDGER_UI_VERSION hledger-$HLEDGER_VERSION hledger-lib-$HLEDGER_LIB_VERSION \ fsnotify-0.3.0.1 @@ -964,39 +964,39 @@ if [[ $(cmpver $(cmd_version hledger-ui) $HLEDGER_UI_VERSION) = 2 ]]; then echo fi -if [[ $(cmpver $(cmd_version hledger-web) $HLEDGER_WEB_VERSION) = 2 ]]; then +if [[ $(cmpver "$(cmd_version hledger-web)" $HLEDGER_WEB_VERSION) = 2 ]]; then echo Installing hledger-web try_install hledger-web-$HLEDGER_WEB_VERSION hledger-$HLEDGER_VERSION hledger-lib-$HLEDGER_LIB_VERSION echo fi -if [[ $(cmpver $(cmd_version hledger-api) $HLEDGER_API_VERSION) = 2 ]]; then +if [[ $(cmpver "$(cmd_version hledger-api)" $HLEDGER_API_VERSION) = 2 ]]; then echo Installing hledger-api try_install hledger-api-$HLEDGER_API_VERSION hledger-$HLEDGER_VERSION hledger-lib-$HLEDGER_LIB_VERSION echo fi # Third-party addons. We allow these to use an older version of -# hledger-lib, in case their bounds have not been updated yet. -if [[ $(cmpver $(cmd_version hledger-diff) $HLEDGER_DIFF_VERSION) = 2 ]]; then +# hledger-lib, in case their bounds have not been updated yet. +if [[ $(cmpver "$(cmd_version hledger-diff)" $HLEDGER_DIFF_VERSION) = 2 ]]; then echo Installing hledger-diff try_install hledger-diff-$HLEDGER_DIFF_VERSION hledger-lib-$HLEDGER_LIB_VERSION echo fi -if [[ $(cmpver $(cmd_version hledger-iadd) $HLEDGER_IADD_VERSION) = 2 ]]; then +if [[ $(cmpver "$(cmd_version hledger-iadd)" $HLEDGER_IADD_VERSION) = 2 ]]; then echo Installing hledger-iadd try_install hledger-iadd-$HLEDGER_IADD_VERSION hledger-lib-$HLEDGER_LIB_VERSION echo fi -if [[ $(cmpver $(cmd_version hledger-interest) $HLEDGER_INTEREST_VERSION) = 2 ]]; then +if [[ $(cmpver "$(cmd_version hledger-interest)" $HLEDGER_INTEREST_VERSION) = 2 ]]; then echo Installing hledger-interest try_install hledger-interest-$HLEDGER_INTEREST_VERSION hledger-lib-$HLEDGER_LIB_VERSION echo fi -if [[ $(cmpver $(cmd_version hledger-irr) $HLEDGER_IRR_VERSION) = 2 ]]; then +if [[ $(cmpver "$(cmd_version hledger-irr)" $HLEDGER_IRR_VERSION) = 2 ]]; then echo Installing hledger-irr try_install hledger-irr-$HLEDGER_IRR_VERSION hledger-lib-$HLEDGER_LIB_VERSION echo