From ea4a0b9d1094f76e3dacbc48f9e34a2a6adf2c37 Mon Sep 17 00:00:00 2001 From: springlie Date: Fri, 10 Feb 2017 16:34:26 +0800 Subject: [PATCH 1/2] fix compatibility error in Zsh, checked with: "zsh ./test.sh" --- spinner.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spinner.sh b/spinner.sh index 423e49b..dac9bdc 100755 --- a/spinner.sh +++ b/spinner.sh @@ -49,7 +49,7 @@ function _spinner() { while : do - printf "\b${sp:i++%${#sp}:1}" + printf "\b${sp:$((i++%${#sp})):1}" sleep $delay done ;; From 24c165108cf3873e118c5e928535556363787629 Mon Sep 17 00:00:00 2001 From: springlie Date: Sat, 11 Feb 2017 03:44:10 +0800 Subject: [PATCH 2/2] fix compatibility error with *BSD echo, checked with: "./test.sh", "sh ./test.sh", "zsh ./test.sh", "bash ./test.sh" --- spinner.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spinner.sh b/spinner.sh index dac9bdc..fceec7a 100755 --- a/spinner.sh +++ b/spinner.sh @@ -39,7 +39,7 @@ function _spinner() { # calculate the column where spinner and status msg will be displayed let column=$(tput cols)-${#2}-8 # display message and position the cursor in $column column - echo -ne ${2} + printf "${2}" printf "%${column}s" # start spinner @@ -55,23 +55,23 @@ function _spinner() { ;; stop) if [[ -z ${3} ]]; then - echo "spinner is not running.." + printf "spinner is not running..\n" exit 1 fi kill $3 > /dev/null 2>&1 # inform the user uppon success or failure - echo -en "\b[" + printf "\b[" if [[ $2 -eq 0 ]]; then - echo -en "${green}${on_success}${nc}" + printf "${green}${on_success}${nc}" else - echo -en "${red}${on_fail}${nc}" + printf "${red}${on_fail}${nc}" fi - echo -e "]" + printf "]\n" ;; *) - echo "invalid argument, try {start/stop}" + printf "invalid argument, try {start/stop}\n" exit 1 ;; esac